aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-10-19 22:12:52 +0200
committerdec05eba <dec05eba@protonmail.com>2021-10-19 22:12:52 +0200
commit9da3c2188060dc982412d7a6e1cd2051b9ddb6a6 (patch)
tree18d7cd9ec63c1f2e42dcda3941907f32e34ac241 /include
parent3bdf82eec2c915e91ae487e29d72639f9efcad67 (diff)
Change from callback to window poll
Diffstat (limited to 'include')
-rw-r--r--include/mgl/graphics/font.h4
-rw-r--r--include/mgl/graphics/image.h28
-rw-r--r--include/mgl/graphics/texture.h15
-rw-r--r--include/mgl/window/event.h10
-rw-r--r--include/mgl/window/window.h23
5 files changed, 61 insertions, 19 deletions
diff --git a/include/mgl/graphics/font.h b/include/mgl/graphics/font.h
index 470662a..6aa9188 100644
--- a/include/mgl/graphics/font.h
+++ b/include/mgl/graphics/font.h
@@ -24,12 +24,12 @@ typedef struct {
struct mgl_font {
mgl_texture texture;
mgl_font_atlas font_atlas;
- unsigned int size;
+ unsigned int character_size;
void *packed_chars;
uint32_t num_packed_chars;
};
-int mgl_font_load_from_file(mgl_font *self, const char *filepath, unsigned int font_size);
+int mgl_font_load_from_file(mgl_font *self, const char *filepath, unsigned int character_size);
void mgl_font_unload(mgl_font *self);
int mgl_font_get_glyph(mgl_font *self, uint32_t codepoint, mgl_font_glyph *glyph);
diff --git a/include/mgl/graphics/image.h b/include/mgl/graphics/image.h
new file mode 100644
index 0000000..b10a028
--- /dev/null
+++ b/include/mgl/graphics/image.h
@@ -0,0 +1,28 @@
+#ifndef MGL_IMAGE_H
+#define MGL_IMAGE_H
+
+#include <stddef.h>
+
+typedef struct mgl_image mgl_image;
+
+typedef enum {
+ MGL_IMAGE_FORMAT_ALPHA,
+ MGL_IMAGE_FORMAT_GRAY,
+ MGL_IMAGE_FORMAT_GRAY_ALPHA,
+ MGL_IMAGE_FORMAT_RGB,
+ MGL_IMAGE_FORMAT_RGBA
+} mgl_image_format;
+
+struct mgl_image {
+ unsigned char *data;
+ int width;
+ int height;
+ mgl_image_format format;
+};
+
+int mgl_image_load_from_file(mgl_image *self, const char *filepath);
+void mgl_image_unload(mgl_image *self);
+
+size_t mgl_image_get_size(mgl_image *self);
+
+#endif /* MGL_IMAGE_H */
diff --git a/include/mgl/graphics/texture.h b/include/mgl/graphics/texture.h
index e6fc97b..3aec07d 100644
--- a/include/mgl/graphics/texture.h
+++ b/include/mgl/graphics/texture.h
@@ -1,16 +1,17 @@
#ifndef MGL_TEXTURE_H
#define MGL_TEXTURE_H
+#include "image.h"
#include <stdbool.h>
typedef struct mgl_texture mgl_texture;
typedef enum {
- MGL_TEXTURE_ALPHA,
- MGL_TEXTURE_GRAY,
- MGL_TEXTURE_GRAY_ALPHA,
- MGL_TEXTURE_RGB,
- MGL_TEXTURE_RGBA
+ MGL_TEXTURE_FORMAT_ALPHA,
+ MGL_TEXTURE_FORMAT_GRAY,
+ MGL_TEXTURE_FORMAT_GRAY_ALPHA,
+ MGL_TEXTURE_FORMAT_RGB,
+ MGL_TEXTURE_FORMAT_RGBA
} mgl_texture_format;
struct mgl_texture {
@@ -27,7 +28,9 @@ typedef struct {
/* |load_options| can be null, in which case the default options are used */
int mgl_texture_load_from_file(mgl_texture *self, const char *filepath, mgl_texture_load_options *load_options);
/* |load_options| can be null, in which case the default options are used */
-int mgl_texture_load_from_memory(mgl_texture *self, const unsigned char *data, int width, int height, mgl_texture_format format, mgl_texture_load_options *load_options);
+int mgl_texture_load_from_image(mgl_texture *self, mgl_image *image, mgl_texture_load_options *load_options);
+/* |load_options| can be null, in which case the default options are used */
+int mgl_texture_load_from_memory(mgl_texture *self, const unsigned char *data, int width, int height, mgl_image_format format, mgl_texture_load_options *load_options);
void mgl_texture_unload(mgl_texture *self);
#endif /* MGL_TEXTURE_H */
diff --git a/include/mgl/window/event.h b/include/mgl/window/event.h
new file mode 100644
index 0000000..2aea478
--- /dev/null
+++ b/include/mgl/window/event.h
@@ -0,0 +1,10 @@
+#ifndef MGL_EVENT_H
+#define MGL_EVENT_H
+
+typedef struct mgl_event mgl_event;
+
+struct mgl_event {
+ int type;
+};
+
+#endif /* MGL_EVENT_H */
diff --git a/include/mgl/window/window.h b/include/mgl/window/window.h
index 5232260..d66fa71 100644
--- a/include/mgl/window/window.h
+++ b/include/mgl/window/window.h
@@ -1,28 +1,29 @@
#ifndef MGL_WINDOW_H
#define MGL_WINDOW_H
+#include "../graphics/color.h"
#include "../system/vec.h"
+#include <stdbool.h>
-typedef struct mgl_window mgl_window;
+typedef struct mgl_event mgl_event;
+/* x11 window handle. TODO: Add others when wayland, etc is added */
+typedef unsigned long mgl_window_handle;
-typedef struct {
- void *userdata;
- void (*draw)(mgl_window *window, void *userdata);
-} mgl_window_callback;
+typedef struct mgl_window mgl_window;
struct mgl_window {
- unsigned long window;
- mgl_window_callback callback;
+ mgl_window_handle window;
mgl_vec2i size;
mgl_vec2i cursor_position;
};
-int mgl_window_create(mgl_window *self, const char *title, int width, int height, mgl_window_callback *callback);
+int mgl_window_create(mgl_window *self, const char *title, int width, int height);
/* if |parent_window| is 0 then the root window is used */
-int mgl_window_create_with_params(mgl_window *self, const char *title, int width, int height, unsigned long parent_window, mgl_window_callback *callback);
+int mgl_window_create_with_params(mgl_window *self, const char *title, int width, int height, mgl_window_handle parent_window);
void mgl_window_deinit(mgl_window *self);
-void mgl_window_events_poll(mgl_window *self);
-void mgl_window_draw(mgl_window *self);
+void mgl_window_clear(mgl_window *self, mgl_color color);
+bool mgl_window_events_poll(mgl_window *self, mgl_event *event);
+void mgl_window_display(mgl_window *self);
#endif /* MGL_WINDOW_H */