I have run into a problem using C++ and OpenGL (GLFW and GLAD). When I use GL_CULL_FACE, it only hides one triangle and it hides it from the front of my cubes. If I use GL_FRONT or GL_BACK, the same thing happens but it only shows the opposite triangles.
These are my vertices and indices that I'm currently using:
static GLfloat vertices[] = {
// front face
0.5, 0.5, -0.5, // 0
-0.5, 0.5, -0.5, // 1
-0.5, -0.5, -0.5, // 2
0.5, -0.5, -0.5, // 3
// right face
0.5, 0.5, -0.5, // 4
0.5, 0.5, 0.5, // 5
0.5, -0.5, 0.5, // 6
0.5, -0.5, -0.5, // 7
// left face
-0.5, 0.5, -0.5, // 8
-0.5, 0.5, 0.5, // 9
-0.5, -0.5, 0.5, // 10
-0.5, -0.5, -0.5, // 11
// back face
0.5, 0.5, 0.5, // 12
-0.5, 0.5, 0.5, // 13
-0.5, -0.5, 0.5, // 14
0.5, -0.5, 0.5, // 15
// top face
0.5, 0.5, -0.5, // 16
-0.5, 0.5, -0.5, // 17
0.5, 0.5, 0.5, // 18
-0.5, 0.5, 0.5, // 19
// bottom face
0.5, -0.5, -0.5, // 20
-0.5, -0.5, -0.5, // 21
0.5, -0.5, 0.5, // 22
-0.5, -0.5, 0.5, // 23
};
static GLuint indices[] = {
20, 23, 22,
23, 21, 20,
16, 19, 18,
19, 17, 16,
12, 14, 15,
14, 13, 12,
8, 10, 11,
10, 9, 8,
4, 6, 7,
6, 5, 4,
0, 2, 3,
2, 1, 0
};
This is how i'm drawing everything:
for (int x = 0; x < 50; x++)
{
for (int z = 0; z < 50; z++)
{
camera.Model = translate(mat4(1.0), vec3(x, 0, z));
glUniformMatrix4fv(matrixID, 1, GL_FALSE, &(camera.Projection * camera.View * camera.Model)[0][0]);
glDrawElements(GL_TRIANGLES, sizeof(indices), GL_UNSIGNED_INT, 0);
}
}
These are my buffers:
GLuint vertexbuffer;
glGenBuffers(1, &vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
GLuint indicesbuffer;
glGenBuffers(1, &indicesbuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indicesbuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
How would I fix this?


