#include #include #include #include #include #include #include #include #include typedef struct { mgl_texture *texture; mgl_font *font; } Userdata; static void draw(mgl_window *window, void *userdata) { mgl_context *context = mgl_get_context(); Userdata *u = userdata; mgl_rectangle rect = { .color = { 255, 0, 0, 255 }, .position = { window->cursor_position.x, window->cursor_position.y }, .size = { 100.0f, 500.0f } }; mgl_rectangle_draw(context, &rect); mgl_sprite sprite; mgl_sprite_init(&sprite, u->texture, 100.0f - 10.0f, 0.0f); mgl_sprite_set_color(&sprite, (mgl_color){255, 255, 255, 128}); mgl_sprite_draw(context, &sprite); mgl_text text; mgl_text_init(&text, u->font, "hello world!\nGood bye world!", 0.0f, 0.0f); mgl_text_draw(context, &text); mgl_text_deinit(&text); } int main(int argc, char **argv) { if(mgl_init() != 0) return 1; mgl_texture texture; mgl_font font; Userdata userdata; userdata.texture = &texture; userdata.font = &font; mgl_window window; if(mgl_window_create(&window, "mgl", 1280, 720) != 0) return 1; if(mgl_texture_load_from_file(&texture, "tests/X11.png", NULL) != 0) return 1; if(mgl_font_load_from_file(&font, "/usr/share/fonts/noto/NotoSans-Regular.ttf", 32) != 0) return 1; mgl_event event; for(;;) { while(mgl_window_events_poll(&window, &event)) { } mgl_window_clear(&window, (mgl_color){0, 0, 0, 255}); draw(&window, &userdata); mgl_window_display(&window); } mgl_font_unload(&font); mgl_texture_unload(&texture); mgl_window_deinit(&window); mgl_deinit(); return 0; }