This repository has been archived on 2023-05-27. You can view files and clone it, but cannot push or open issues or pull requests.
api8/src/light.c

67 lines
1.6 KiB
C
Raw Normal View History

#include "../includes/animations.h"
void cube(int, int);
void lights(int state) {
static GLuint quadId = 0;
static GLuint pId = 0;
switch (state) {
case GL4DH_INIT:
quadId = gl4dgGenQuadf();
pId = gl4duCreateProgram("<vs>shaders/lights.vs", "<fs>shaders/lights.fs",
NULL);
gl4duGenMatrix(GL_FLOAT, "proj");
gl4duGenMatrix(GL_FLOAT, "mod");
gl4duGenMatrix(GL_FLOAT, "view");
glEnable(GL_DEPTH_TEST);
break;
case GL4DH_DRAW:
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
static GLdouble lumloc = 0.;
// clang-format off
GLfloat rouge[] = {1.f, 0.f, 0.f, 1.f},
blanc[] = {1.f, 1.f, 1.f, 1.f},
lumpos0[] = {4.f * (float)sin(lumloc), 0.f, 1.1f, 1.f},
lumpos[4],
*mat,
ratio = (GLfloat)_dims[0] / (GLfloat)_dims[1];
// clang-format on
// Setup
gl4duBindMatrix("proj");
gl4duLoadIdentityf(); // TODO: ça bug??
gl4duFrustumf(-ratio, ratio, -1, 1, 2, 100);
// Scene
gl4duBindMatrix("view");
gl4duLoadIdentityf();
gl4duLookAtf(0, 0, 4.0f, 0, 0, 0, 0.0f, 1.0f, 0);
mat = (GLfloat *)gl4duGetMatrixData();
MMAT4XVEC4(lumpos, mat, lumpos0);
gl4duBindMatrix("mod");
gl4duLoadIdentityf();
glUseProgram(pId);
gl4duSendMatrices();
glUniform4fv(glGetUniformLocation(pId, "scolor"), 1, rouge);
glUniform4fv(glGetUniformLocation(pId, "lcolor"), 1, blanc);
glUniform4fv(glGetUniformLocation(pId, "lumpos"), 1, lumpos);
gl4dgDraw(quadId);
glUseProgram(0);
break;
default:
break;
}
}