Remove dimensions, fondu(). Add polygone()

This commit is contained in:
Mylloon 2022-05-17 21:04:38 +02:00
parent 907ed3c174
commit 56503dcc18
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
7 changed files with 120 additions and 112 deletions

View file

@ -3,16 +3,13 @@
#include <GL4D/gl4dh.h> #include <GL4D/gl4dh.h>
// Dimensions initiales de la fenêtre
extern int dimensions[];
// Cube coloré qui tourne sur lui-même // Cube coloré qui tourne sur lui-même
void cube(int); void cube(int);
// Voronoi // Voronoi GPU
void voronoi(int); void voronoi(int);
// Effet de transition en fondu // Formes en jouant avec caméra et polygones
void fondu(void (*)(int), void (*)(int), Uint32, Uint32, int); void polygone(int);
#endif #endif

View file

@ -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);
}

11
shaders/polygone.fs Normal file
View file

@ -0,0 +1,11 @@
/* TP4 */
#version 330
uniform vec3 couleur;
out vec4 fragColor;
void main(void) {
fragColor = vec4(couleur, 1.);
}

14
shaders/polygone.vs Normal file
View file

@ -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.);
}

View file

@ -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);
}

View file

@ -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("<vs>shaders/transition.vs", "<fs>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;
}
}

92
src/polygone.c Normal file
View file

@ -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("<vs>shaders/polygone.vs", "<fs>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;
}
}