fixing zoom padding
This commit is contained in:
parent
44a2d5aab3
commit
017d021824
@ -6,16 +6,13 @@ layout (location = 0) in vec2 aPos;
|
|||||||
layout (location = 1) in vec2 texPos;
|
layout (location = 1) in vec2 texPos;
|
||||||
|
|
||||||
uniform vec2 camPos;
|
uniform vec2 camPos;
|
||||||
uniform int zoom;
|
uniform float zoom;
|
||||||
|
|
||||||
float invLerp( float a, float b, float v ){
|
float invLerp( float a, float b, float v ){
|
||||||
return (v - a) / (b - a);
|
return (v - a) / (b - a);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
gl_Position = vec4(
|
gl_Position = vec4(zoom * (aPos + vec2(camPos.x, -camPos.y) * 2 / zoom), 0.0, 1.0);
|
||||||
(aPos + vec2(camPos.x, -camPos.y) * 2) * (invLerp(-10, 10, zoom) * 2),
|
|
||||||
0.0,
|
|
||||||
1.0) ;
|
|
||||||
TexPos = texPos;
|
TexPos = texPos;
|
||||||
}
|
}
|
||||||
|
7
zoomer.c
7
zoomer.c
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include "stb_image.h"
|
#include "stb_image.h"
|
||||||
|
|
||||||
SDL_Window *w;
|
SDL_Window *w;
|
||||||
SDL_Renderer *r;
|
SDL_Renderer *r;
|
||||||
|
|
||||||
@ -128,7 +129,7 @@ int main(int argc, char *argv[])
|
|||||||
SDL_Event e;
|
SDL_Event e;
|
||||||
float camPos[2] = {0.};
|
float camPos[2] = {0.};
|
||||||
float mousePos[2] = {0.};
|
float mousePos[2] = {0.};
|
||||||
int zoom = 0;
|
float zoom = 1;
|
||||||
int tick = 0;
|
int tick = 0;
|
||||||
while(!shouldClose){
|
while(!shouldClose){
|
||||||
while(SDL_PollEvent(&e)){
|
while(SDL_PollEvent(&e)){
|
||||||
@ -155,7 +156,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEWHEEL:
|
case SDL_MOUSEWHEEL:
|
||||||
zoom += e.wheel.y;
|
zoom += e.wheel.y/10.;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,7 +164,7 @@ int main(int argc, char *argv[])
|
|||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glUniform2f(glGetUniformLocation(pshader, "camPos"), camPos[0], camPos[1]);
|
glUniform2f(glGetUniformLocation(pshader, "camPos"), camPos[0], camPos[1]);
|
||||||
glUniform2f(glGetUniformLocation(pshader, "mousePos"), mousePos[0], mousePos[1]);
|
glUniform2f(glGetUniformLocation(pshader, "mousePos"), mousePos[0], mousePos[1]);
|
||||||
glUniform1i(glGetUniformLocation(pshader, "zoom"), zoom);
|
glUniform1f(glGetUniformLocation(pshader, "zoom"), zoom);
|
||||||
glUniform1i(glGetUniformLocation(pshader, "tick"), tick);
|
glUniform1i(glGetUniformLocation(pshader, "tick"), tick);
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user