Culling fonctionnel et correction de sens de certains quads

This commit is contained in:
Marc-Eric Martel 2021-10-06 21:32:12 -04:00
parent e7fe266e80
commit 256685e141
2 changed files with 44 additions and 42 deletions

View File

@ -22,6 +22,10 @@ void Engine::Init()
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_CULL_FACE);
// Cull!
glCullFace(GL_BACK);
// Light
GLfloat light0Pos[4] = { 0.0f, CHUNK_SIZE_Y, 0.0f, 1.0f };
@ -36,14 +40,12 @@ void Engine::Init()
glLightfv(GL_LIGHT0, GL_SPECULAR, light0Spec);
// Lumière de Skybox.
GLfloat light1Pos[4] = { 0.0f, 0.0f, 0.0f, 2.0f };
GLfloat light1Amb[4] = { 1.5f, 1.5f, 1.5f, 1.5f };
GLfloat light1Diff[4] = { 1.f, 1.f, 1.f, 1.f };
GLfloat light1Spec[4] = { 1.f, 1.f, 1.f, 1.0f };
glLightfv(GL_LIGHT1, GL_POSITION, light1Pos);
GLfloat light1Emi[4] = { 2.f, 2.f, 2.f, 2.f };
glLightfv(GL_LIGHT1, GL_AMBIENT, light1Amb);
glLightfv(GL_LIGHT1, GL_DIFFUSE, light1Diff);
glLightfv(GL_LIGHT1, GL_SPECULAR, light1Spec);
glLightfv(GL_LIGHT1, GL_EMISSION, light1Emi);
// Blend
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -94,59 +96,59 @@ void Engine::Render(float elapsedTime)
glEnable(GL_LIGHT1);
glBegin(GL_QUADS);
glTexCoord2f(0, .5f);
glVertex3f(5.f, -5.f, 5.f);
glTexCoord2f(.25f, .5f);
glVertex3f(-5.f, -5.f, 5.f);
glTexCoord2f(.25f, .75f);
glVertex3f(-5.f, 5.f, 5.f);
glTexCoord2f(0, .75f);
glVertex3f(5.f, 5.f, 5.f);
glTexCoord2f(.25f, .75f);
glVertex3f(-5.f, 5.f, 5.f);
glTexCoord2f(.25f, .50f);
glVertex3f(-5.f, -5.f, 5.f);
glTexCoord2f(0, .50f);
glVertex3f(5.f, -5.f, 5.f);
glTexCoord2f(.25f, .75f);
glVertex3f(-5.f, 5.f, 5.f);
glTexCoord2f(.50f, .75f);
glVertex3f(-5.f, 5.f, -5.f);
glTexCoord2f(.50f, .50f);
glTexCoord2f(.25f, .5f);
glVertex3f(-5.f, -5.f, 5.f);
glTexCoord2f(.50f, .5f);
glVertex3f(-5.f, -5.f, -5.f);
glTexCoord2f(.25f, .50f);
glVertex3f(-5.f, -5.f, 5.f);
glTexCoord2f(.50f, .75f);
glVertex3f(-5.f, 5.f, -5.f);
glTexCoord2f(.75f, .75f);
glVertex3f(5.f, 5.f, -5.f);
glTexCoord2f(.75f, .50f);
glTexCoord2f(.25f, .75f);
glVertex3f(-5.f, 5.f, 5.f);
glTexCoord2f(.50f, .5f);
glVertex3f(-5.f, -5.f, -5.f);
glTexCoord2f(.75f, .5f);
glVertex3f(5.f, -5.f, -5.f);
glTexCoord2f(.50f, .50f);
glVertex3f(-5.f, -5.f, -5.f);
glTexCoord2f(.75f, .75f);
glVertex3f(5.f, 5.f, -5.f);
glTexCoord2f(.50f, .75f);
glVertex3f(-5.f, 5.f, -5.f);
glTexCoord2f(.75f, .5f);
glVertex3f(5.f, -5.f, -5.f);
glTexCoord2f(1, .5f);
glVertex3f(5.f, -5.f, 5.f);
glTexCoord2f(1, .75f);
glVertex3f(5.f, 5.f, 5.f);
glTexCoord2f(1, .50f);
glVertex3f(5.f, -5.f, 5.f);
glTexCoord2f(.75f, .50f);
glVertex3f(5.f, -5.f, -5.f);
glTexCoord2f(.75f, .75f);
glVertex3f(5.f, 5.f, -5.f);
glTexCoord2f(.25f, 1);
glVertex3f(5.f, 5.f, 5.f);
glTexCoord2f(.50f, 1);
glVertex3f(5.f, 5.f, -5.f);
glTexCoord2f(.50f, 1);
glVertex3f(5.f, 5.f, 5.f);
glTexCoord2f(.50f, .75f);
glVertex3f(-5.f, 5.f, -5.f);
glTexCoord2f(.25f, .75f);
glVertex3f(-5.f, 5.f, 5.f);
glTexCoord2f(.25f, .75f);
glVertex3f(-5.f, 5.f, -5.f);
glTexCoord2f(.50f, .50f);
glVertex3f(-5.f, -5.f, -5.f);
glTexCoord2f(.75f, .50f);
glVertex3f(5.f, -5.f, -5.f);
glTexCoord2f(.75f, .25f);
glVertex3f(5.f, -5.f, 5.f);
glTexCoord2f(.50f, .25f);
glVertex3f(-5.f, -5.f, 5.f);
glTexCoord2f(.75f, .25f);
glVertex3f(5.f, -5.f, 5.f);
glTexCoord2f(.75f, .5f);
glVertex3f(5.f, -5.f, -5.f);
glTexCoord2f(.50f, .5f);
glVertex3f(-5.f, -5.f, -5.f);
glEnd();
glEnable(GL_DEPTH_TEST);
@ -246,13 +248,13 @@ void Engine::Render(float elapsedTime)
glNormal3f(0, -1, 0);
glTexCoord2f(0, 0);
glVertex3f(-0.5f, -0.5f, -0.5f);
glTexCoord2f(0, 1);
glVertex3f(-0.5f, -0.5f, 0.5f);
glTexCoord2f(0, 1);
glVertex3f(-0.5f, -0.5f, -0.5f);
glTexCoord2f(1, 1);
glVertex3f(0.5f, -0.5f, 0.5f);
glTexCoord2f(1, 0);
glVertex3f(0.5f, -0.5f, -0.5f);
glTexCoord2f(1, 0);
glVertex3f(0.5f, -0.5f, 0.5f);
glDisable(GL_BLEND);
glEnd();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 432 KiB