diff options
Diffstat (limited to 'src/window')
-rw-r--r-- | src/window/window.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/window/window.c b/src/window/window.c index 9a650ae..44e0a23 100644 --- a/src/window/window.c +++ b/src/window/window.c @@ -32,10 +32,11 @@ static void mgl_window_on_resize(mgl_window *self, int width, int height) { mgl_context *context = mgl_get_context(); self->size.x = width; self->size.y = height; - context->gl.glViewport(0, 0, self->size.x, self->size.y); - context->gl.glMatrixMode(GL_PROJECTION); - context->gl.glLoadIdentity(); - context->gl.glOrtho(0.0, width, height, 0.0, -1.0, 1.0); + + mgl_view view; + view.position = (mgl_vec2i){ 0, 0 }; + view.size = self->size; + mgl_window_set_view(self, &view, NULL); } int mgl_window_create(mgl_window *self, const char *title, int width, int height) { @@ -288,3 +289,14 @@ void mgl_window_display(mgl_window *self) { context->gl.glXSwapBuffers(context->connection, self->window); } +void mgl_window_set_view(mgl_window *self, mgl_view *new_view, mgl_view *prev_view) { + if(prev_view) + *prev_view = self->view; + + mgl_context *context = mgl_get_context(); + self->view = *new_view; + context->gl.glViewport(new_view->position.x, self->size.y - new_view->size.y - new_view->position.y, new_view->size.x, new_view->size.y); + context->gl.glMatrixMode(GL_PROJECTION); + context->gl.glLoadIdentity(); + context->gl.glOrtho(0.0, new_view->size.x, new_view->size.y, 0.0, 0.0, 1.0); +} |