aboutsummaryrefslogtreecommitdiff
path: root/src/window
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-11-03 16:53:03 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-03 20:34:22 +0100
commitf26a606bf50f7dbe35c79bfa52f2026bd7af3eb8 (patch)
tree1c0a35e3cea48ffe989a366b685da65d274ff0af /src/window
parentdef772cc0efd7c22c6154c6d9f73df1a08fa2671 (diff)
Add viewport
Diffstat (limited to 'src/window')
-rw-r--r--src/window/window.c20
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);
+}