From 017d021824b336be90e537642ff705d1defd4ff2 Mon Sep 17 00:00:00 2001
From: Anthony Debucquoy <debucquoy.anthony@gmail.com>
Date: Mon, 24 Jun 2024 17:15:20 +0200
Subject: [PATCH] fixing zoom padding

---
 vshader.glsl | 7 ++-----
 zoomer.c     | 7 ++++---
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/vshader.glsl b/vshader.glsl
index 938e113..9ba77fd 100644
--- a/vshader.glsl
+++ b/vshader.glsl
@@ -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;
 }
diff --git a/zoomer.c b/zoomer.c
index 1583bfb..a7da014 100644
--- a/zoomer.c
+++ b/zoomer.c
@@ -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);