From f26a606bf50f7dbe35c79bfa52f2026bd7af3eb8 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 3 Nov 2021 16:53:03 +0100 Subject: Add viewport --- tests/main.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/main.c b/tests/main.c index 6a69866..99a8398 100644 --- a/tests/main.c +++ b/tests/main.c @@ -55,30 +55,41 @@ static void draw(mgl_window *window, void *userdata) { mgl_vertex_buffer_set_position(u->vertex_buffer2, (mgl_vec2f){ window->cursor_position.x, window->cursor_position.y + 500 }); mgl_vertex_buffer_draw(context, u->vertex_buffer2, &u->font->texture); + mgl_vec2i view_size = { + .x = 200, + .y = 200 + }; + + mgl_view prev_view; + mgl_view new_view = { + .position = { window->size.x/2 - view_size.x/2, window->size.y/2 - view_size.y/2 }, + .size = view_size + }; + mgl_window_set_view(window, &new_view, &prev_view); mgl_vertex vertices[4] = { (mgl_vertex){ - .position = {window->cursor_position.x, 0.0f}, + .position = {-new_view.position.x + window->cursor_position.x, -new_view.position.y + window->cursor_position.y}, .texcoords = {0.0f, 0.0f}, - .color = {0, 255, 0, 255} + .color = {255, 0, 0, 255} }, (mgl_vertex){ - .position = {window->cursor_position.x + 100.0f, 0.0f}, + .position = {-new_view.position.x + window->cursor_position.x + 400.0f, -new_view.position.y + window->cursor_position.y}, .texcoords = {0.0f, 0.0f}, .color = {0, 255, 0, 255}, }, (mgl_vertex){ - .position = {window->cursor_position.x + 100.0f, 100.0f}, + .position = {-new_view.position.x + window->cursor_position.x + 400.0f, -new_view.position.y + window->cursor_position.y + 400.0f}, .texcoords = {0.0f, 0.0f}, - .color = {0, 255, 0, 255}, + .color = {0, 0, 255, 255}, }, (mgl_vertex){ - .position = {window->cursor_position.x, 100.0f}, + .position = {-new_view.position.x + window->cursor_position.x, -new_view.position.y + window->cursor_position.y + 400.0f}, .texcoords = {0.0f, 0.0f}, - .color = {0, 255, 0, 255} + .color = {255, 255, 0, 255} } }; - mgl_vertices_draw(context, vertices, 4, MGL_PRIMITIVE_QUADS); + mgl_window_set_view(window, &prev_view, NULL); } int main(int argc, char **argv) { -- cgit v1.2.3