diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-10-16 07:34:47 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-10-16 07:34:47 +0200 |
commit | 1952897a8cb411d9b10d75ac6a8c223924c07e09 (patch) | |
tree | 098414ec3216870a7e4145ba6d4c0c77c9206880 | |
parent | 97f1b1c735775d1e22412bbcf98ef403f9ee2275 (diff) |
Fix resize event sometimes not triggered (set window gravity)
-rw-r--r-- | X11.png | bin | 107373 -> 8173 bytes | |||
-rw-r--r-- | include/mgl/graphics/texture.h | 9 | ||||
-rw-r--r-- | src/graphics/texture.c | 4 | ||||
-rw-r--r-- | src/window.c | 3 | ||||
-rw-r--r-- | tests/main.c | 5 |
5 files changed, 14 insertions, 7 deletions
Binary files differ diff --git a/include/mgl/graphics/texture.h b/include/mgl/graphics/texture.h index 7048c20..f859554 100644 --- a/include/mgl/graphics/texture.h +++ b/include/mgl/graphics/texture.h @@ -1,6 +1,8 @@ #ifndef MGL_TEXTURE_H #define MGL_TEXTURE_H +#include <stdbool.h> + typedef struct mgl_texture mgl_texture; typedef enum { @@ -17,7 +19,12 @@ struct mgl_texture { mgl_texture_format format; }; -int mgl_texture_load_from_file(mgl_texture *self, const char *filepath); +typedef struct { + bool compressed; +} mgl_texture_load_options; + +/* |load_options| can be null, in which case default options are used */ +int mgl_texture_load_from_file(mgl_texture *self, const char *filepath, mgl_texture_load_options *load_options); void mgl_texture_unload(mgl_texture *self); #endif /* MGL_TEXTURE_H */ diff --git a/src/graphics/texture.c b/src/graphics/texture.c index ebc4e58..b3a1fab 100644 --- a/src/graphics/texture.c +++ b/src/graphics/texture.c @@ -41,7 +41,7 @@ static int mgl_texture_format_to_source_opengl_format(mgl_texture_format format) /* TODO: Ensure texture is power of 2 if the hardware doesn't support non power of two textures */ /* TODO: Verify if source format should always be 4 components (RGBA) because apparently if its another format then opengl will internally convert it to RGBA */ -int mgl_texture_load_from_file(mgl_texture *self, const char *filepath) { +int mgl_texture_load_from_file(mgl_texture *self, const char *filepath, mgl_texture_load_options *load_options) { self->id = 0; int format; @@ -59,7 +59,7 @@ int mgl_texture_load_from_file(mgl_texture *self, const char *filepath) { return -1; } - const int opengl_texture_format = mgl_texture_format_to_compressed_opengl_format(self->format); + const int opengl_texture_format = load_options && load_options->compressed ? mgl_texture_format_to_compressed_opengl_format(self->format) : mgl_texture_format_to_opengl_format(self->format); context->gl.glBindTexture(GL_TEXTURE_2D, self->id); context->gl.glTexImage2D(GL_TEXTURE_2D, 0, opengl_texture_format, self->width, self->height, 0, mgl_texture_format_to_source_opengl_format(self->format), GL_UNSIGNED_BYTE, image_data); diff --git a/src/window.c b/src/window.c index 818805d..62f7e88 100644 --- a/src/window.c +++ b/src/window.c @@ -56,8 +56,9 @@ int mgl_window_create_with_params(mgl_window *self, const char *title, int width XSetWindowAttributes window_attr; window_attr.colormap = color_map; window_attr.event_mask = KeyPressMask | StructureNotifyMask; + window_attr.bit_gravity = NorthWestGravity; - self->window = XCreateWindow(context->connection, parent_window, 0, 0, width, height, 0, ((XVisualInfo*)context->visual_info)->depth, InputOutput, ((XVisualInfo*)context->visual_info)->visual, CWColormap | CWEventMask, &window_attr); + self->window = XCreateWindow(context->connection, parent_window, 0, 0, width, height, 0, ((XVisualInfo*)context->visual_info)->depth, InputOutput, ((XVisualInfo*)context->visual_info)->visual, CWColormap | CWEventMask | CWBitGravity, &window_attr); XFreeColormap(context->connection, color_map); if(!self->window) { fprintf(stderr, "XCreateWindow failed\n"); diff --git a/tests/main.c b/tests/main.c index 0b4c559..2154b2b 100644 --- a/tests/main.c +++ b/tests/main.c @@ -18,11 +18,10 @@ static void draw(mgl_window *window, void *userdata) { .position = { 0.0f, 0.0f }, .size = { 100.0f, 500.0f } }; - mgl_rectangle_draw(context, &rect); mgl_sprite sprite; - mgl_sprite_init(&sprite, u->texture, 10.0f, 0.0f); + mgl_sprite_init(&sprite, u->texture, 100.0f - 10.0f, 0.0f); mgl_sprite_set_color(&sprite, 1.0f, 1.0f, 1.0f, 0.5f); mgl_sprite_draw(context, &sprite); } @@ -44,7 +43,7 @@ int main(int argc, char **argv) { if(mgl_window_create(&window, "mgl", 1280, 720, &window_callback) != 0) return 1; - if(mgl_texture_load_from_file(&texture, "X11.png") != 0) + if(mgl_texture_load_from_file(&texture, "X11.png", NULL) != 0) return 1; for(;;) { |