From 61c7efc6dd2a036b5d14aa223d06a18cb7d1388e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 16 Nov 2021 03:54:26 +0100 Subject: Sprite: add rotation and origin --- tests/main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/main.c b/tests/main.c index 3dc8c98..f76f384 100644 --- a/tests/main.c +++ b/tests/main.c @@ -34,9 +34,16 @@ static void draw(mgl_window *window, void *userdata) { mgl_shader_program_set_uniform_vec2f(u->shader_program, "resolution", (mgl_vec2f){ u->texture->width, u->texture->height }); + static float rot = 0.0f; + rot += 5.0f; + mgl_sprite sprite; - mgl_sprite_init(&sprite, u->texture, 100.0f - 10.0f, 0.0f); + mgl_sprite_init(&sprite, u->texture); + mgl_sprite_set_position(&sprite, (mgl_vec2f){ 100.0f - 10.0f + u->texture->width * 0.5f * 2.0f, u->texture->height * 0.5f * 2.0f }); mgl_sprite_set_color(&sprite, (mgl_color){255, 255, 255, 128}); + mgl_sprite_set_rotation(&sprite, rot); + mgl_sprite_set_origin(&sprite, (mgl_vec2f){ u->texture->width * 0.5f, u->texture->height * 0.5f }); + sprite.scale = (mgl_vec2f){ 2.0f, 2.0f }; mgl_shader_program_use(u->shader_program); mgl_sprite_draw(context, &sprite); mgl_shader_program_use(NULL); @@ -213,7 +220,7 @@ int main(int argc, char **argv) { if(mgl_texture_init(&texture) != 0) return 1; - if(mgl_texture_load_from_file(&texture, "tests/X11.jpg", &(mgl_texture_load_options){ false, true }) != 0) + if(mgl_texture_load_from_file(&texture, "tests/X11.jpg", &(mgl_texture_load_options){ false, false }) != 0) return 1; if(mgl_mapped_file_load("/usr/share/fonts/noto/NotoSans-Regular.ttf", &font_file, &(mgl_memory_mapped_file_load_options){ .readable = true, .writable = false }) != 0) -- cgit v1.2.3