colors!
This commit is contained in:
parent
34def9d200
commit
c4c49aa04a
3 changed files with 30 additions and 10 deletions
|
@ -1,8 +1,10 @@
|
|||
#version 330
|
||||
|
||||
in float il;
|
||||
in float intensite_eclairage;
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform vec4 couleur;
|
||||
|
||||
void main() {
|
||||
fragColor = il * vec4(0.35f, 0.35f, 0.43f, 1.0f);
|
||||
fragColor = intensite_eclairage * couleur;
|
||||
}
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
layout(location = 0) in vec3 pos;
|
||||
layout(location = 1) in vec3 normal;
|
||||
|
||||
out float il;
|
||||
out float intensite_eclairage;
|
||||
uniform mat4 proj, model, view;
|
||||
|
||||
void main() {
|
||||
vec3 Ld = normalize(vec3(0.0, -0.2, -1.0));
|
||||
vec3 n = normalize(transpose(inverse(view * model)) * vec4(normal, 0.0)).xyz;
|
||||
il = clamp(dot(n, -Ld), 0.0, 1.0);
|
||||
intensite_eclairage = clamp(dot(n, -Ld), 0.0, 1.0);
|
||||
gl_Position = proj * view * model * vec4(pos, 1.0);
|
||||
}
|
||||
|
|
30
src/manif.c
30
src/manif.c
|
@ -2,6 +2,11 @@
|
|||
|
||||
static GLuint _pId = 0;
|
||||
static GLuint _planId = 0;
|
||||
static GLuint _herosId = 0;
|
||||
|
||||
static const char matrix_proj[] = "proj";
|
||||
static const char matrix_model[] = "model";
|
||||
static const char matrix_view[] = "view";
|
||||
|
||||
static void init(void);
|
||||
static void draw(void);
|
||||
|
@ -23,12 +28,13 @@ void manif(int state) {
|
|||
|
||||
static void init(void) {
|
||||
_planId = gl4dgGenQuadf();
|
||||
_herosId = gl4dgGenConef(3, GL_FALSE);
|
||||
_pId =
|
||||
gl4duCreateProgram("<vs>shaders/manif.vs", "<fs>shaders/manif.fs", NULL);
|
||||
|
||||
gl4duGenMatrix(GL_FLOAT, "proj");
|
||||
gl4duGenMatrix(GL_FLOAT, "model");
|
||||
gl4duGenMatrix(GL_FLOAT, "view");
|
||||
gl4duGenMatrix(GL_FLOAT, matrix_proj);
|
||||
gl4duGenMatrix(GL_FLOAT, matrix_model);
|
||||
gl4duGenMatrix(GL_FLOAT, matrix_view);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
@ -38,23 +44,35 @@ static void draw(void) {
|
|||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glUseProgram(_pId);
|
||||
|
||||
gl4duBindMatrix("proj");
|
||||
const GLfloat couleur_plan[] = {0.3f, 0.3f, 0.3f, 1};
|
||||
const GLfloat couleur_heros[] = {1, 1, 0, 1};
|
||||
GLint couleur_loc = glGetUniformLocation(_pId, "couleur");
|
||||
|
||||
gl4duBindMatrix(matrix_proj);
|
||||
gl4duLoadIdentityf();
|
||||
GLfloat ratio = (GLfloat)_dims[0] / (GLfloat)_dims[1];
|
||||
gl4duFrustumf(-1, 1, -ratio, ratio, 1, 1000);
|
||||
|
||||
gl4duBindMatrix("view");
|
||||
gl4duBindMatrix(matrix_view);
|
||||
gl4duLoadIdentityf();
|
||||
const GLfloat distance = 2;
|
||||
gl4duLookAtf(0, distance, distance, 0, 0, 0, 0, 1, 0);
|
||||
|
||||
gl4duBindMatrix("model");
|
||||
gl4duBindMatrix(matrix_model);
|
||||
gl4duLoadIdentityf();
|
||||
gl4duRotatef(-90, 1, 0, 0);
|
||||
gl4duScalef(4 * distance, 2 * distance, 1);
|
||||
|
||||
gl4duSendMatrices();
|
||||
glUniform4fv(couleur_loc, 1, couleur_plan);
|
||||
gl4dgDraw(_planId);
|
||||
|
||||
gl4duBindMatrix(matrix_model);
|
||||
gl4duLoadIdentityf();
|
||||
|
||||
gl4duSendMatrices();
|
||||
glUniform4fv(couleur_loc, 1, couleur_heros);
|
||||
gl4dgDraw(_herosId);
|
||||
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
|
Reference in a new issue