try to zoom (not working)

This commit is contained in:
Mylloon 2023-05-19 12:09:54 +02:00
parent 9ca3af3b82
commit d7036e5b79
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 73 additions and 9 deletions

View file

@ -1,4 +1,10 @@
#version 330
uniform sampler2D tex;
in vec2 vsoTexCoord;
out vec4 fragColor;
void main(void) {
fragColor = texture(tex, vsoTexCoord);
}

View file

@ -1,4 +1,14 @@
#version 330
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);
}

View file

@ -3,8 +3,10 @@
/* Mise-à-jour des animations en fonction du son */
static void update_with_audio(void (*)(int), void (*)(int), int);
static void zoom_in_init(void);
static void zoom_in_draw(void);
static GLuint _zoomin_pId = 0, _zoomin_tId = 0, _zoomin_tex[2];
static void zoomin_init(void);
static void zoomin_draw(void (*)(int), void (*)(int), Uint32, Uint32, int);
static void zoomin_deinit(void);
static void update_with_audio(void (*a0)(int), void (*a1)(int), int state) {
if (a0) {
@ -19,11 +21,15 @@ static void update_with_audio(void (*a0)(int), void (*a1)(int), int state) {
void zoom_in(void (*a0)(int), void (*a1)(int), Uint32 t, Uint32 et, int state) {
switch (state) {
case GL4DH_INIT:
zoom_in_init();
zoomin_init();
break;
case GL4DH_DRAW:
zoom_in_draw();
zoomin_draw(a0, a1, t, et, state);
break;
case GL4DH_FREE:
zoomin_deinit();
break;
case GL4DH_UPDATE_WITH_AUDIO:
@ -35,10 +41,52 @@ void zoom_in(void (*a0)(int), void (*a1)(int), Uint32 t, Uint32 et, int state) {
}
}
static void zoom_in_init(void) {
static GLuint _pId = 0;
_pId = gl4duCreateProgram("<vs>shaders/zoom_in.vs", "<fs>shaders/zoom_in.fs",
NULL);
static void zoomin_init(void) {
int vp[4];
glGetIntegerv(GL_VIEWPORT, vp);
glGenTextures(2, _zoomin_tex);
for (int i = 0; i < 2; ++i) {
glBindTexture(GL_TEXTURE_2D, _zoomin_tex[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, vp[2], vp[3], 0, GL_RGBA,
GL_UNSIGNED_BYTE, NULL);
}
_zoomin_pId = gl4duCreateProgram("<vs>shaders/zoom_in.vs",
"<fs>shaders/zoom_in.fs", NULL);
}
static void zoom_in_draw(void) {}
static void zoomin_draw(void (*a0)(int), void (*a1)(int), Uint32 t, Uint32 et,
int state) {
glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
(GLint *)&_zoomin_tId);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
_zoomin_tex[0], 0);
if (a0) {
a0(state);
}
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
_zoomin_tex[1], 0);
if (a1) {
a1(state);
}
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
_zoomin_tId, 0);
glUseProgram(_zoomin_pId);
glUniform1f(glGetUniformLocation(_zoomin_pId, "zoomAmount"),
(GLfloat)et / (GLfloat)t);
glUniform1i(glGetUniformLocation(_zoomin_pId, "tex"), 0);
}
static void zoomin_deinit(void) {
if (_zoomin_tex[0]) {
glDeleteTextures(2, _zoomin_tex);
_zoomin_tex[0] = _zoomin_tex[1] = 0;
}
}