OpenGL Can't figure out vertex winding

This topic is 1294 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm working on a project with OpenGL and am trying to figure out vertex winding. I understand that, by default OpenGL considers faces where the vertices are "wound" counter-clock wise are front facing. I've built a cube out of individual faces, however, OpenGL keeps culling them away...which I have narrowed down to being a vertex winding issue.

Currently, for the front face (pointing towards the +z axis, camera is pointing down the -z axis) is wound as such:
0-----2
|     /
|   /
1 /
0
/ |
/  |
/   |
1------2

Which, to me....looks counter clockwise. However, the triangles are only visible when I turn on glCullFace(GL_FRONT). Does it have something to do with the direction that the final edge connection is going?

Is there something I'm not understanding about what is considered front-facing or something with counter-clock wise winding?

Note: I'm rendering with GL_TRIANGLES Edited by CirdanValen

Share on other sites

Currently, for the front face (pointing towards the +z axis, camera is pointing down the -z axis) is wound as such:

if the triangle is pointing towards the +z axis, then the vertex order from the camera view is:

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


Therefor clockwise. Could this be the fault ?

Edited by Ashaman73

Share on other sites

This is the result with default culling settings (remove back faces, frontface = CCW)

With this setup:

void addPlaneSouth(const glm::vec3& offset = glm::vec3(0.f),
const glm::vec3& rotation = glm::vec3(0.f),
float scale = 1.f)
{
growVertexArray(6);
uint32 index = _currentMesh->vertexCount;

// Top right
_currentMesh->vertexArray[index++] = Vertex((0.5f*scale) + offset.x,
(-0.5f*scale) + offset.y,
(0.5f*scale) + offset.z,
1.f, 0.f);

// Bottom right
_currentMesh->vertexArray[index++] = Vertex((0.5f*scale) + offset.x,
(0.5f*scale) + offset.y,
(0.5f*scale) + offset.z,
0.f, 1.f);

// Top left
_currentMesh->vertexArray[index++] = Vertex((-0.5f*scale) + offset.x,
(-0.5f*scale) + offset.y,
(0.5f*scale) + offset.z,
0.f, 0.f);

// Triangle 2

// Top left
_currentMesh->vertexArray[index++] = Vertex((-0.5f*scale) + offset.x,
(-0.5f*scale) + offset.y,
(0.5f*scale) + offset.z,
1.f, 0.f);

// Bottom left
_currentMesh->vertexArray[index++] = Vertex((-0.5f*scale) + offset.x,
(0.5f*scale) + offset.y,
(0.5f*scale) + offset.z,
0.f, 1.f);

// Bottom right
_currentMesh->vertexArray[index++] = Vertex((0.5f*scale) + offset.x,
(0.5f*scale) + offset.y,
(0.5f*scale) + offset.z,
1.f, 1.f);

_currentMesh->vertexCount += 6;

}


Share on other sites

Ok, first analyse your both tris in world space (do not consider the camera):

Tri1 (according to your corner naming)
2-----0
\   |
\  |    CW
1

Tri 2
0
| \    CCW !
|   \
1----2


Now view it from the camera (looking along the negative z-axis:

Tri 1
0---- 2
|   /
|  /     CCW !
1

Tri 2
0
/ |    CW
/  |
2---1


You use two different vertex orders, therefor only one tri is visible, and that should be Tri 1(front face is CCW and backface is CW , which get culled)

But, isn't your up-vector looking along the positive y-axis ?

Then your naming would be wrong and the tris would look like this (world space):

Tri1
1
/ |  CCW
/  |
2---0

Tri 2
1----2
|   /  CW
| /
0



In this case, if your camera would look along the positive z axis, you would  see the Tri 1.

So, double check your camera setup, for each corner and tri use unique corner colors to track the issue down.

Share on other sites

Okay, thanks for the tips...I think I figured it out. Instead of thinking about winding around the center of the triangle, it helps to think about it winding around the quad. By default -y was up, so I ended up rotating the view matrix.

1. 1
2. 2
3. 3
frob
20
4. 4
Rutin
19
5. 5

• 32
• 13
• 10
• 11
• 9
• Forum Statistics

• Total Topics
632558
• Total Posts
3007077

×