feat(renderer): backface culling

This commit is contained in:
maelstrom 2025-03-05 23:18:09 +01:00
parent ac89dea966
commit 23ac7ee634
2 changed files with 44 additions and 38 deletions

View file

@ -2,42 +2,43 @@
static float CUBE_VERTICES[] = {
// positions // normals // texture coords
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
-0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
-0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
-0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f,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-0.0, -0.0, 0.0, 1.0,
0.5, -0.5, 0.5, -0.0, -0.0, 1.0, 1.0, 0.0,
-0.5, -0.5, 0.5, -0.0, -0.0, 1.0, 0.0, 0.0,
0.5, 0.5, 0.5, -0.0, -0.0, 1.0, 1.0, 1.0,
0.5, 0.5, -0.5, -0.0, 1.0, -0.0, 1.0, 1.0,
0.5, 0.5, 0.5, -0.0, 1.0, -0.0, 1.0, 0.0,
-0.5, 0.5, -0.5, -0.0, 1.0, -0.0, 0.0, 1.0,
};
static float SPHERE_VERTICES[] = {

View file

@ -67,6 +67,9 @@ void renderInit(GLFWwindow* window, int width, int height) {
void renderParts() {
glDepthMask(GL_TRUE);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glFrontFace(GL_CW);
// Use shader
shader->use();
@ -129,12 +132,13 @@ void renderParts() {
shader->set("texScale", part->size);
CUBE_MESH->bind();
glDrawArrays(GL_TRIANGLES, 0, 36);
glDrawArrays(GL_TRIANGLES, 0, CUBE_MESH->vertexCount);
}
}
void renderSkyBox() {
glDepthMask(GL_FALSE);
glCullFace(GL_FRONT);
skyboxShader->use();
@ -155,6 +159,7 @@ void renderHandles() {
if (!editorToolHandles->adornee.has_value() || !editorToolHandles->active) return;
glDepthMask(GL_TRUE);
glCullFace(GL_BACK);
// Use shader
handleShader->use();