From 4aa7273eea642bff78477b0b220c7056628b13a8 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 10 Oct 2021 17:29:31 +0200 Subject: Add texture loading (and render in test) --- tests/main.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/main.c b/tests/main.c index c16a68e..fdd6cfe 100644 --- a/tests/main.c +++ b/tests/main.c @@ -1,10 +1,18 @@ #include #include #include +#include + #include #include +typedef struct { + mgl_texture *texture; +} Userdata; + static void draw(mgl_window *window, void *userdata) { + Userdata *u = userdata; + glBegin(GL_QUADS); glColor3f(1., 0., 0.); glVertex3f(-.75, -.75, 0.); glColor3f(0., 1., 0.); glVertex3f( .75, -.75, 0.); @@ -18,25 +26,42 @@ static void draw(mgl_window *window, void *userdata) { glColor4f(1., 0., 0., 0.5); glVertex3f(0.1 + .75, 0.1 + .75, 0.); glColor4f(1., 0., 0., 0.5); glVertex3f(0.1 + -.75, 0.1 + .75, 0.); glEnd(); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glBindTexture(GL_TEXTURE_2D, u->texture->id); + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f); + glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f + 0.1f, -1.0f, 0.0f); + glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f + 0.1f, -1.0f + 0.1f, 0.0f); + glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, -1.0f + 0.1f, 0.0f); + glEnd(); + glBindTexture(GL_TEXTURE_2D, 0); } int main(int argc, char **argv) { if(mgl_init() != 0) return 1; + mgl_texture texture; mgl_window_callback window_callback; window_callback.draw = draw; + Userdata userdata; + userdata.texture = &texture; + mgl_window window; - if(mgl_window_create(&window, "mgl", 1280, 720, &window_callback, NULL) != 0) + if(mgl_window_create(&window, "mgl", 1280, 720, &window_callback, &userdata) != 0) + return 1; + + if(mgl_texture_load_from_file(&texture, "X11.png") != 0) return 1; - mgl_window_show(&window); for(;;) { - mgl_window_event_poll(&window); + mgl_window_events_poll(&window); mgl_window_draw(&window); } + mgl_texture_unload(&texture); mgl_window_deinit(&window); mgl_deinit(); return 0; -- cgit v1.2.3