86 lines
2.2 KiB
C
86 lines
2.2 KiB
C
#include <GL4D/gl4duw_SDL2.h>
|
|
#include <stdio.h>
|
|
|
|
static void init(void);
|
|
static void resize(int, int);
|
|
static void draw(void);
|
|
static void sortie(void);
|
|
|
|
static GLuint _wW = 1280, _wH = 720;
|
|
static GLuint _quadId = 0;
|
|
static GLuint _pId = 0;
|
|
|
|
int main(int argc, char **argv) {
|
|
if (!gl4duwCreateWindow(argc, argv, "Demo API8 2023", GL4DW_POS_CENTERED,
|
|
GL4DW_POS_CENTERED, _wW, _wH,
|
|
GL4DW_OPENGL | GL4DW_SHOWN)) {
|
|
fprintf(stderr, "Erreur lors de la création de la fenêtre.\n");
|
|
return 1;
|
|
}
|
|
|
|
init();
|
|
atexit(sortie);
|
|
gl4duwResizeFunc(resize);
|
|
gl4duwDisplayFunc(draw);
|
|
gl4duwMainLoop();
|
|
|
|
return 0;
|
|
}
|
|
|
|
void init(void) {
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
|
_quadId = gl4dgGenQuadf();
|
|
_pId = gl4duCreateProgram("<vs>shaders/lights.vs", "<fs>shaders/lights.fs",
|
|
NULL);
|
|
glEnable(GL_DEPTH_TEST);
|
|
gl4duGenMatrix(GL_FLOAT, "proj");
|
|
gl4duGenMatrix(GL_FLOAT, "mod");
|
|
gl4duGenMatrix(GL_FLOAT, "view");
|
|
resize(_wW, _wH);
|
|
}
|
|
|
|
static void resize(int width, int height) {
|
|
GLfloat ratio;
|
|
_wW = width;
|
|
_wH = height;
|
|
glViewport(0, 0, _wW, _wH);
|
|
ratio = (GLfloat)_wW / (GLfloat)_wH;
|
|
gl4duBindMatrix("proj");
|
|
gl4duLoadIdentityf();
|
|
gl4duFrustumf(-1 * ratio, 1 * ratio, -1, 1, 2, 100);
|
|
}
|
|
|
|
void draw(void) {
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
// Vue
|
|
gl4duBindMatrix("view");
|
|
gl4duLoadIdentityf();
|
|
gl4duLookAtf(0, 0, 4.f, 0, 0, 0, 0.f, 1.f, 0);
|
|
|
|
// Scene
|
|
// clang-format off
|
|
GLfloat rouge[] = {1.f, 0.f, 0.f, 1.f},
|
|
blanc[] = {1.f, 1.f, 1.f, 1.f},
|
|
lumpos0[] = {0.f, 0.f, 1.1f, 1.f},
|
|
lumpos[4],
|
|
*mat;
|
|
// clang-format on
|
|
|
|
static GLdouble x = 0.;
|
|
lumpos0[0] = 4.f * (float)sin(x);
|
|
gl4duBindMatrix("view");
|
|
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);
|
|
}
|
|
|
|
void sortie(void) { gl4duClean(GL4DU_ALL); }
|