diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/main.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/main.c b/tests/main.c index 1675439..8631c35 100644 --- a/tests/main.c +++ b/tests/main.c @@ -7,10 +7,12 @@ #include <mgl/graphics/sprite.h> #include <mgl/graphics/font.h> #include <mgl/graphics/text.h> +#include <mgl/graphics/vertex_buffer.h> typedef struct { mgl_texture *texture; mgl_font *font; + mgl_vertex_buffer *vertex_buffer; } Userdata; static void draw(mgl_window *window, void *userdata) { @@ -33,6 +35,9 @@ static void draw(mgl_window *window, void *userdata) { mgl_text_init(&text, u->font, "hello world!\nGood bye world!", 0.0f, 0.0f); mgl_text_draw(context, &text); mgl_text_deinit(&text); + + mgl_vertex_buffer_set_position(u->vertex_buffer, (mgl_vec2f){ window->cursor_position.x, window->cursor_position.y }); + mgl_vertex_buffer_draw(context, u->vertex_buffer, &u->font->texture); } int main(int argc, char **argv) { @@ -41,10 +46,12 @@ int main(int argc, char **argv) { mgl_texture texture; mgl_font font; + mgl_vertex_buffer vertex_buffer; Userdata userdata; userdata.texture = &texture; userdata.font = &font; + userdata.vertex_buffer = &vertex_buffer; mgl_window window; if(mgl_window_create(&window, "mgl", 1280, 720) != 0) @@ -56,6 +63,37 @@ int main(int argc, char **argv) { if(mgl_font_load_from_file(&font, "/usr/share/fonts/noto/NotoSans-Regular.ttf", 32) != 0) return 1; + if(mgl_vertex_buffer_init(&vertex_buffer, MGL_PRIMITIVE_QUADS, MGL_USAGE_STATIC) != 0) + return 1; + + mgl_vertex vertices[4] = { + (mgl_vertex){ + .position = {0.0f, 0.0f}, + .color = {255, 0, 0, 100}, + .texcoords = {0.0f, 0.0f} + }, + (mgl_vertex){ + .position = {font.texture.width, 0.0f}, + .color = {0, 255, 0, 100}, + .texcoords = {1.0f, 0.0f} + }, + (mgl_vertex){ + .position = {font.texture.width, font.texture.height}, + .color = {0, 0, 255, 100}, + .texcoords = {1.0f, 1.0f} + }, + (mgl_vertex){ + .position = {0.0f, font.texture.height}, + .color = {255, 0, 255, 100}, + .texcoords = {0.0f, 1.0f} + } + }; + + if(mgl_vertex_buffer_update(&vertex_buffer, vertices, 4) != 0) + return 1; + + fprintf(stderr, "Font texture width: %d, texture height: %d\n", font.texture.width, font.texture.height); + mgl_event event; for(;;) { while(mgl_window_poll_event(&window, &event)) { @@ -67,6 +105,7 @@ int main(int argc, char **argv) { mgl_window_display(&window); } + mgl_vertex_buffer_deinit(&vertex_buffer); mgl_font_unload(&font); mgl_texture_unload(&texture); mgl_window_deinit(&window); |