0

In OpenGL, the default setup is:

  1. Co-ordinate system = right handed, with +x->right, +y->up, +z->towards-viewer.
  2. Therefore, a postive rotation around z will move the x basis vector to y (anti-clockwise).
  3. Front-facing polygons are defined as CCW vertices.
  4. Culling of backface faces is achieved by:
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

Ok, we all know this. In Flash 11/Molehill/Stage3d, the defaults are supposed to be the same.

However, if I enable backface culling in step 4 via:

c3d.setCulling(Context3DTriangleFace.BACK);

my faces are culled. It seems the default is Context3DTriangleFace.FRONT. I created a sanity-check case in OpenGL and Stage3D which are otherwise identical. Same vertex/index list, leave defaults, same orthographic projection matrix, identity ModelView, yet I have to set culling to FRONT not BACK.

It's as if Stage3D has a different winding default. i.e. it's as if, under the hood, OpengGL has been set to: glFrontFace(GL_CW); instead of OpenGLs default: glFrontFace(GL_CCW);

Has anyone else come across this? It's driving me nuts...

Shane
  • 3,051
  • 3
  • 40
  • 45

2 Answers2

1

I meant to answer this ages ago, but forgot, so I'll just answer it now.

I was right, Stage3D considers front-facing to be a CW winding in screen-space, as opposed to OpenGL's CCW. I hope this helps anyone coming from OpenGL. Just reverse the order of your index buffer indices, or change the culling mode to FRONT. I decided to change the index order.

Cheers,

Shane

Shane
  • 3,051
  • 3
  • 40
  • 45
0

Perhaps one has a front face clockwise and the other counter-clockwise. glFrontFace(GL_CW); or glFrontFace(GL_CCW);

Robert Rouhani
  • 14,512
  • 6
  • 44
  • 59
  • This is what I'm thinking too, however unlike OpenGL, there is no way to define this in Molehill. :| – Shane Dec 30 '11 at 19:57
  • If there's no binding in Stage3d, the solution there would be to then set the Stage3D culling to the front face (as weird as that sounds, your front face is facing away from the camera). That or you could flip the order of your indices so that `0, 1, 2` becomes `0, 2, 1` – Robert Rouhani Dec 30 '11 at 23:36
  • Setting culling to FRONT will obviously work, as will changing the winding of the indices, but it's just so wrong (or I should say just-so-non-default). In clip-space, the vertices are CCW, hence facing the viewer, so to set the culling to FRONT makes me cringe. – Shane Dec 31 '11 at 01:11
  • From what I've read, Stage3D uses the left-handed coordinate system and it wants to keep that as the default. The difference in clip space between left and right handed coordinate systems makes it so that the CW face is actually facing the viewer. If you absolutely have to have a right-handed system, you can modify the projection matrix to convert the left handed coordinates to right handed ones: http://www.geometrictools.com/Documentation/LeftHandedToRightHanded.pdf – Robert Rouhani Dec 31 '11 at 01:23
  • Also here's another StackOverflow question dealing with that same conversion in an easier to understand way: http://stackoverflow.com/q/1263072/1122135 – Robert Rouhani Dec 31 '11 at 01:26
  • Where did you read that Stage3D is left handed? Besides, at the end of the day, the hardware just multiples matrices, and I give it a RH projection matrix, which is why, with no culling, every renders exactly the same as my OpenGL code. – Shane Dec 31 '11 at 03:55
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/6272/discussion-between-robert-rouhani-and-shane) – Robert Rouhani Dec 31 '11 at 04:07