From dda5e2cab04a509ee532fac214eeff7222ab479d Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 19 May 2023 13:01:20 +0200 Subject: [PATCH] wow the zoom is fonctionning --- shaders/zoom_in.fs | 14 +++++++++++--- shaders/zoom_in.vs | 5 +---- src/animations.c | 18 +++++++++++++++--- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/shaders/zoom_in.fs b/shaders/zoom_in.fs index f8f5eda..bdec4f2 100644 --- a/shaders/zoom_in.fs +++ b/shaders/zoom_in.fs @@ -1,10 +1,18 @@ #version 330 -uniform sampler2D tex; +uniform sampler2D tex0; +uniform sampler2D tex1; +uniform float zoom; in vec2 vsoTexCoord; out vec4 fragColor; -void main(void) { - fragColor = texture(tex, vsoTexCoord); +void main() { + vec2 center = vec2(0.5); + vec2 zoomedTexCoord = mix(center, vsoTexCoord, zoom); + + vec4 color1 = texture(tex0, vsoTexCoord); + vec4 color2 = texture(tex1, zoomedTexCoord); + + fragColor = mix(color1, color2, smoothstep(0., 1., zoom)); } diff --git a/shaders/zoom_in.vs b/shaders/zoom_in.vs index acb688a..4193e5e 100644 --- a/shaders/zoom_in.vs +++ b/shaders/zoom_in.vs @@ -3,12 +3,9 @@ layout(location = 0) in vec3 vsiPosition; layout(location = 2) in vec2 vsiTexCoord; -uniform float zoomAmount; - out vec2 vsoTexCoord; void main(void) { gl_Position = vec4(vsiPosition, 1.0); - - vsoTexCoord = vec2(vsiTexCoord.s * zoomAmount, vsiTexCoord.t * zoomAmount); + vsoTexCoord = vsiTexCoord; } diff --git a/src/animations.c b/src/animations.c index a1ac3bf..f6abfba 100644 --- a/src/animations.c +++ b/src/animations.c @@ -84,11 +84,23 @@ static void zoomin_draw(void (*a0)(int), void (*a1)(int), Uint32 t, Uint32 et, glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _zoomin_tId, 0); + glDisable(GL_DEPTH_TEST); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, _zoomin_tex[0]); + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, _zoomin_tex[1]); + glUseProgram(_zoomin_pId); - glUniform1f(glGetUniformLocation(_zoomin_pId, "zoomAmount"), - (GLfloat)et / (GLfloat)t); - glUniform1i(glGetUniformLocation(_zoomin_pId, "tex"), 0); + GLfloat zoom = (GLfloat)et / (GLfloat)t; + glUniform1f(glGetUniformLocation(_zoomin_pId, "zoom"), (1.f - zoom)); + glUniform1i(glGetUniformLocation(_zoomin_pId, "tex1"), 0); + glUniform1i(glGetUniformLocation(_zoomin_pId, "tex0"), 1); gl4dgDraw(_quadId); + + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, 0); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, 0); } static void zoomin_deinit(void) {