Update viewport according to the window size
Also dynamically change the resolution for the shaders
This commit is contained in:
parent
0b7b6fdf7b
commit
757e64e16f
|
@ -1,4 +1,5 @@
|
|||
te
|
||||
ded
|
||||
SDL2
|
||||
*.exe
|
||||
*.obj
|
||||
|
|
13
src/main.c
13
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) {
|
||||
|
|
Loading…
Reference in New Issue