fixing zoom padding

This commit is contained in:
Debucquoy Anthony 2024-06-24 17:15:20 +02:00
parent 44a2d5aab3
commit 017d021824
Signed by: tonitch
GPG Key ID: A78D6421F083D42E
2 changed files with 6 additions and 8 deletions

View File

@ -6,16 +6,13 @@ layout (location = 0) in vec2 aPos;
layout (location = 1) in vec2 texPos;
uniform vec2 camPos;
uniform int zoom;
uniform float zoom;
float invLerp( float a, float b, float v ){
return (v - a) / (b - a);
}
void main(){
gl_Position = vec4(
(aPos + vec2(camPos.x, -camPos.y) * 2) * (invLerp(-10, 10, zoom) * 2),
0.0,
1.0) ;
gl_Position = vec4(zoom * (aPos + vec2(camPos.x, -camPos.y) * 2 / zoom), 0.0, 1.0);
TexPos = texPos;
}

View File

@ -8,6 +8,7 @@
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
SDL_Window *w;
SDL_Renderer *r;
@ -128,7 +129,7 @@ int main(int argc, char *argv[])
SDL_Event e;
float camPos[2] = {0.};
float mousePos[2] = {0.};
int zoom = 0;
float zoom = 1;
int tick = 0;
while(!shouldClose){
while(SDL_PollEvent(&e)){
@ -155,7 +156,7 @@ int main(int argc, char *argv[])
}
break;
case SDL_MOUSEWHEEL:
zoom += e.wheel.y;
zoom += e.wheel.y/10.;
break;
}
}
@ -163,7 +164,7 @@ int main(int argc, char *argv[])
glClear(GL_COLOR_BUFFER_BIT);
glUniform2f(glGetUniformLocation(pshader, "camPos"), camPos[0], camPos[1]);
glUniform2f(glGetUniformLocation(pshader, "mousePos"), mousePos[0], mousePos[1]);
glUniform1i(glGetUniformLocation(pshader, "zoom"), zoom);
glUniform1f(glGetUniformLocation(pshader, "zoom"), zoom);
glUniform1i(glGetUniformLocation(pshader, "tick"), tick);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);