Add kirby scene
This commit is contained in:
parent
a8bb74ed6f
commit
af51348b09
6 changed files with 120 additions and 0 deletions
BIN
images/kirby.jpg
Normal file
BIN
images/kirby.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 62 KiB |
|
@ -14,4 +14,7 @@ void voronoi(int);
|
||||||
// Formes en jouant avec caméra et polygones
|
// Formes en jouant avec caméra et polygones
|
||||||
void polygone(int);
|
void polygone(int);
|
||||||
|
|
||||||
|
// Kirby
|
||||||
|
void kirby(int);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
10
shaders/kirby.fs
Normal file
10
shaders/kirby.fs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#version 330
|
||||||
|
|
||||||
|
uniform sampler2D tex;
|
||||||
|
|
||||||
|
in vec2 vsoTexCoord;
|
||||||
|
out vec4 fragColor;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
fragColor = texture(tex, vsoTexCoord);
|
||||||
|
}
|
15
shaders/kirby.vs
Normal file
15
shaders/kirby.vs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#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 view;
|
||||||
|
|
||||||
|
out vec2 vsoTexCoord;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_Position = proj * view * vec4(pos, 1.);
|
||||||
|
vsoTexCoord = vec2(texCoord.x, 1 - texCoord.y);
|
||||||
|
}
|
91
src/kirby.c
Normal file
91
src/kirby.c
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
/* TP 5 */
|
||||||
|
|
||||||
|
#include "../includes/animations.h"
|
||||||
|
|
||||||
|
#include <SDL_image.h>
|
||||||
|
|
||||||
|
void kirby(int etat) {
|
||||||
|
static GLuint boule = 0, proc_id = 0, tex_id = 0;
|
||||||
|
static GLfloat musique[3] = {0};
|
||||||
|
|
||||||
|
switch(etat) {
|
||||||
|
case GL4DH_INIT:
|
||||||
|
boule = gl4dgGenSpheref(20, 20);
|
||||||
|
|
||||||
|
SDL_Surface *image = IMG_Load("images/kirby.jpg");
|
||||||
|
SDL_Surface *surface = SDL_CreateRGBSurface(0, image->w, image->h, 32, R_MASK, G_MASK, B_MASK, A_MASK);
|
||||||
|
SDL_BlitSurface(image, NULL, surface, NULL);
|
||||||
|
SDL_FreeSurface(image);
|
||||||
|
|
||||||
|
glGenTextures(1, &tex_id);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex_id);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);
|
||||||
|
SDL_FreeSurface(surface);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
|
proc_id = gl4duCreateProgram("<vs>shaders/kirby.vs", "<fs>shaders/kirby.fs", NULL);
|
||||||
|
|
||||||
|
gl4duGenMatrix(GL_FLOAT, "proj");
|
||||||
|
gl4duGenMatrix(GL_FLOAT, "view");
|
||||||
|
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GL4DH_DRAW:
|
||||||
|
glClearColor(.66f, .17f, .24f, 1.f);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
glUseProgram(proc_id);
|
||||||
|
|
||||||
|
gl4duBindMatrix("proj");
|
||||||
|
gl4duLoadIdentityf();
|
||||||
|
gl4duFrustumf(-1.f, 1.f, -.57f, .57f, 1.f, 1000.f);
|
||||||
|
|
||||||
|
gl4duBindMatrix("view");
|
||||||
|
gl4duLoadIdentityf();
|
||||||
|
|
||||||
|
gl4duLookAtf(2.f, 0.f, 2.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f);
|
||||||
|
|
||||||
|
gl4duPushMatrix();
|
||||||
|
|
||||||
|
gl4duRotatef(135, 0, 1, 0);
|
||||||
|
|
||||||
|
GLfloat s = moyenneMusique() * 5000.f;
|
||||||
|
if(musique[0] != 0 || musique[1] != 0) {
|
||||||
|
s = (s - musique[0]) / (musique[1] - musique[0]) + .2f;
|
||||||
|
if(s > musique[2]) {
|
||||||
|
s -= s / 20.f;
|
||||||
|
}
|
||||||
|
if(s < musique[2]) {
|
||||||
|
s += s / 20.f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
musique[1] = musique[1] < s ? s : musique[1];
|
||||||
|
musique[0] = musique[0] > s ? s : musique[0];
|
||||||
|
musique[2] = s;
|
||||||
|
|
||||||
|
gl4duPushMatrix();
|
||||||
|
if(musique[1] != musique[0]) {
|
||||||
|
gl4duScalef(s, s, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
|
gl4duSendMatrices();
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex_id);
|
||||||
|
glUniform1i(glGetUniformLocation(proc_id, "tex"), 0);
|
||||||
|
|
||||||
|
gl4dgDraw(boule);
|
||||||
|
gl4duPopMatrix();
|
||||||
|
|
||||||
|
glUseProgram(0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
1
window.c
1
window.c
|
@ -26,6 +26,7 @@ int main(int argc, char *argv[]) {
|
||||||
{ 6800, cube, NULL, NULL },
|
{ 6800, cube, NULL, NULL },
|
||||||
{ 8500, voronoi, NULL, NULL },
|
{ 8500, voronoi, NULL, NULL },
|
||||||
{ 6000, polygone, NULL, NULL },
|
{ 6000, polygone, NULL, NULL },
|
||||||
|
{ 5000, kirby, NULL, NULL },
|
||||||
{ 0, NULL, NULL, NULL }
|
{ 0, NULL, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Reference in a new issue