ded

Dramatic EDitor
Index Commits Files Refs README LICENSE
commit 757e64e16f8e643dc90ea4faedc2f9709b6a7dd7
parent 0b7b6fdf7bceed017a907660e6a4794fe74a29db
Author: rexim <reximkut@gmail.com>
Date:   Tue,  6 Jul 2021 20:39:52 +0700

Update viewport according to the window size

Also dynamically change the resolution for the shaders

Diffstat:
M.gitignore | 1+
Msrc/main.c | 13+++++++++----
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,4 +1,5 @@
 te
+ded
 SDL2
 *.exe
 *.obj
diff --git a/src/main.c b/src/main.c
@@ -75,7 +75,7 @@ void usage(FILE *stream)
 // TODO: Delete line
 // TODO: Split the line on Enter
 
-// #define OPENGL_RENDERER
+#define OPENGL_RENDERER
 
 #ifdef OPENGL_RENDERER
 void MessageCallback(GLenum source,
@@ -246,8 +246,6 @@ int main(int argc, char **argv)
 
         time_uniform = glGetUniformLocation(program, "time");
         resolution_uniform = glGetUniformLocation(program, "resolution");
-
-        glUniform2f(resolution_uniform, SCREEN_WIDTH, SCREEN_HEIGHT);
     }
 
     // Init Font Texture
@@ -327,6 +325,13 @@ int main(int argc, char **argv)
             }
         }
 
+        {
+            int w, h;
+            SDL_GetWindowSize(window, &w, &h);
+            glViewport(0, 0, w, h);
+            glUniform2f(resolution_uniform, (float) w, (float) h);
+        }
+
         glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
         glClear(GL_COLOR_BUFFER_BIT);
 
@@ -439,7 +444,7 @@ int main(int argc, char **argv)
 
             case SDL_MOUSEBUTTONDOWN: {
                 Vec2f mouse_click = vec2f((float) event.button.x, (float) event.button.y);
-                switch(event.button.button) { 
+                switch(event.button.button) {
                 case SDL_BUTTON_LEFT: {
                     Vec2f cursor_click = vec2f_add(mouse_click, vec2f_sub(camera_pos, vec2f_div(window_size(window), vec2fs(2.0f))));
                     if(cursor_click.x > 0.0f && cursor_click.y > 0.0f) {