diff --git a/includes/animations.h b/includes/animations.h index 199a179..7bdf82a 100644 --- a/includes/animations.h +++ b/includes/animations.h @@ -3,16 +3,13 @@ #include -// Dimensions initiales de la fenêtre -extern int dimensions[]; - // Cube coloré qui tourne sur lui-même void cube(int); -// Voronoi +// Voronoi GPU void voronoi(int); -// Effet de transition en fondu -void fondu(void (*)(int), void (*)(int), Uint32, Uint32, int); +// Formes en jouant avec caméra et polygones +void polygone(int); #endif diff --git a/shaders/fondu.fs b/shaders/fondu.fs deleted file mode 100644 index 360bef9..0000000 --- a/shaders/fondu.fs +++ /dev/null @@ -1,14 +0,0 @@ -/* Auteur : Farès BELHADJ (amsi@up8.edu) */ - -#version 330 - -uniform float delta_temps; -uniform sampler2D tex0; -uniform sampler2D tex1; - -in vec2 vsoTexCoord; -out vec4 fragColor; - -void main(void) { - fragColor = mix(texture(tex0, vsoTexCoord), texture(tex1, vsoTexCoord), delta_temps); -} diff --git a/shaders/polygone.fs b/shaders/polygone.fs new file mode 100644 index 0000000..18fb5b4 --- /dev/null +++ b/shaders/polygone.fs @@ -0,0 +1,11 @@ +/* TP4 */ + +#version 330 + +uniform vec3 couleur; + +out vec4 fragColor; + +void main(void) { + fragColor = vec4(couleur, 1.); +} diff --git a/shaders/polygone.vs b/shaders/polygone.vs new file mode 100644 index 0000000..85d40eb --- /dev/null +++ b/shaders/polygone.vs @@ -0,0 +1,14 @@ +/* TP4 */ + +#version 330 + +layout(location = 0) in vec3 pos; +layout(location = 1) in vec3 normal; +layout(location = 2) in vec2 texCoord; + +uniform mat4 proj; +uniform mat4 modview; + +void main(void) { + gl_Position = proj * modview * vec4(pos, 1.); +} diff --git a/shaders/transition.vs b/shaders/transition.vs deleted file mode 100644 index 5f6fa05..0000000 --- a/shaders/transition.vs +++ /dev/null @@ -1,14 +0,0 @@ -/* Auteur : Farès BELHADJ (amsi@up8.edu) */ - -#version 330 - -layout (location = 0) in vec3 vsiPosition; -layout (location = 1) in vec3 vsiNormal; -layout (location = 2) in vec2 vsiTexCoord; - -out vec2 vsoTexCoord; - -void main(void) { - gl_Position = vec4(vsiPosition, 1.); - vsoTexCoord = vec2(vsiTexCoord.s, vsiTexCoord.t); -} diff --git a/src/fondu.c b/src/fondu.c deleted file mode 100644 index 0946360..0000000 --- a/src/fondu.c +++ /dev/null @@ -1,78 +0,0 @@ -/* Auteur : Farès BELHADJ (amsi@up8.edu) */ - -#include "../includes/animations.h" - -void fondu(void (*ancienne_anim)(int), void (*nouvelle_anim)(int), Uint32 temps_total, Uint32 temps_ecoule, int etat) { - GLint viewport[4]; - GLint tex_id = 0; - static GLuint ecran[2], proc_id = 0, quad = 0; - - switch(etat) { - case GL4DH_INIT: - quad = gl4dgGenQuadf(); - - glGetIntegerv(GL_VIEWPORT, viewport); - glGenTextures(2, ecran); - for(int i = 0; i < 2; ++i) { - glBindTexture(GL_TEXTURE_2D, ecran[i]); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, viewport[2], viewport[3], 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - } - - proc_id = gl4duCreateProgram("shaders/transition.vs", "shaders/fondu.fs", NULL); - break; - - case GL4DH_UPDATE_WITH_AUDIO: - break; - - case GL4DH_DRAW: - // Récupération ID texture - glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &tex_id); - - // Dessine les deux animations - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ecran[0], 0); - if(ancienne_anim) { - ancienne_anim(etat); - } - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ecran[1], 0); - if(nouvelle_anim) { - nouvelle_anim(etat); - } - - // Mix des deux écrans - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, (GLuint)tex_id, 0); - glDisable(GL_DEPTH); - glUseProgram(proc_id); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, ecran[0]); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, ecran[1]); - - glUniform1f(glGetUniformLocation(proc_id, "delta_temps"), temps_ecoule / (GLfloat)temps_total); - glUniform1i(glGetUniformLocation(proc_id, "tex0"), 0); - glUniform1i(glGetUniformLocation(proc_id, "tex1"), 1); - gl4dgDraw(quad); - - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, 0); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, 0); - break; - - case GL4DH_FREE: - if(ecran[0] || ecran[1]) { - glDeleteTextures(2, ecran); - ecran[0] = ecran[1] = 0; - } - break; - - default: - break; - } -} diff --git a/src/polygone.c b/src/polygone.c new file mode 100644 index 0000000..415fa23 --- /dev/null +++ b/src/polygone.c @@ -0,0 +1,92 @@ +/* TP4 */ + +#include "../includes/animations.h" + +void polygone(int etat) { + static GLuint proc_id = 0, cube = 0, sphere = 0, tore = 0; + GLint color = 0; + static double couleurs[6]; + + static GLfloat a = 0, b = 0; + + switch(etat) { + case GL4DH_INIT: + cube = gl4dgGenCubef(); + sphere = gl4dgGenSpheref(10, 10); + tore = gl4dgGenTorusf(15, 15, 1.5); + + proc_id = gl4duCreateProgram("shaders/polygone.vs", "shaders/polygone.fs", NULL); + + gl4duGenMatrix(GL_FLOAT, "modview"); + gl4duGenMatrix(GL_FLOAT, "proj"); + + for(int i = 0; i < 6; ++i) { + couleurs[i] = gl4dmURand(); + } + break; + + case GL4DH_UPDATE_WITH_AUDIO: + break; + + case GL4DH_DRAW: + glClearColor(.0f, .0f, .5f, 1.f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glUseProgram(proc_id); + + gl4duBindMatrix("proj"); + gl4duLoadIdentityf(); + gl4duFrustumf(-1, 1, -0.63, 0.63, 1, 1000); + + gl4duBindMatrix("modview"); + gl4duLoadIdentityf(); + gl4duTranslatef(0, 0, -5); + + for(int i = 0; i < 2; ++i) { + gl4duPushMatrix(); + gl4duRotatef(a, 0, 1, 0); + if(i % 2) { + gl4duRotatef(a, 0, 0, 1); + } else { + gl4duRotatef(a, 1, 0, 0); + } + color = glGetUniformLocation(proc_id, "couleur"); + gl4duLookAtf(1, 1, 1, 0, 0, 0, 0, 0, 1); + glUniform3f(color, couleurs[i], couleurs[i + 1], couleurs[i + 2]); + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + gl4duSendMatrix(); + gl4dgDraw(cube); + gl4duPopMatrix(); + } + + gl4duPushMatrix(); + gl4duRotatef(b, 0, 1, 0); + color = glGetUniformLocation(proc_id, "couleur"); + glUniform3f(color, couleurs[2], couleurs[3], couleurs[4]); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + gl4duSendMatrix(); + gl4dgDraw(sphere); + gl4duPopMatrix(); + + gl4duPushMatrix(); + gl4duRotatef(a + b, 0, 1, 0); + color = glGetUniformLocation(proc_id, "couleur"); + glUniform3f(color, couleurs[3], couleurs[4], couleurs[5]); + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + gl4duSendMatrix(); + gl4dgDraw(tore); + gl4duPopMatrix(); + gl4duSendMatrices(); + + glUseProgram(0); + + a += 1; + b += 2; + break; + + case GL4DH_FREE: + break; + + default: + break; + } +}