glCullFace is not correctly working, do you have answers for that?

Viewed 137

I am rendering a terrain and because the underside will never be seen I though face culling would bring a nice performance boost. I looked up a tutorial and came to these settings:

glCullFace(GL_FRONT);
glFrontFace(GL_CCW);

The problem is, that this is only working partially. The terrain is made out of quadrilaterals which each consist out of two right triangles and I only see one of the two triangles, if I use clockwise winding, I see the other triangle. I am using indices to safe memory and I have drawn out on paper how the windings of the indices should be but somehow it isn't working.

I generate my indices like this:

mapIndices[arrayIdx + 0] = i;
mapIndices[arrayIdx + 1] = i + 1;
mapIndices[arrayIdx + 2] = i + CHUNK_SIDE_LENGHT + 1;

mapIndices[arrayIdx + 5] = mapIndices[arrayIdx + 1];
mapIndices[arrayIdx + 4] = mapIndices[arrayIdx + 2];
mapIndices[arrayIdx + 3] = mapIndices[arrayIdx + 2] + 1;

Don't get confused over the CHUNK_SIDE_LENGHT + 1, I want CHUNK_SIDE_LENGHT triangles, so I need CHUNK_SIDE_LENGHT + 1 vertices for one row. As I said, I have drawn this order on paper and the winding is correct but OpenGL doesn't like it. Could this have something to do with the index rendering?

1 Answers

I cannot see any issue in your code.

The winding order of the 1st triangle is the same

0 : i
1 : i + 1
2 : i + CHUNK_SIDE_LENGHT + 1

2
 +
 | \
 |   \
 |     \         
 +-------+
0         1

as the winding order of the 2nd triangle:

3 : i + CHUNK_SIDE_LENGHT + 2
4 : i + CHUNK_SIDE_LENGHT + 1
5 : i + 1

4         3
 +-------+
   \     | 
     \   |
       \ |
         +
          5
Related