Primary Navigation

Tech Off Post

Single Post Permalink

With regard to the different faces of the cube getting rendered problem, I've found that that some of the faces in the CreateTestCube() method do not obey the clockwise winding rule that was briefly talked about in the article. If you want to see these faces
correctly you have to do a couple of things...

First you have to fix up the offending faces so that when the camera is looking at each face from outside the cube, the vertices that form each individual triangle trace out a clockwise path.

Second, since back-face culling is currently turned off you have to turn it on and set it to cull faces that have counter-clockwise orientation (imagine being inside the cube and trying to look out...all of the faces will be oriented the wrong way so wont be
drawn etc). To do this, replace line 108 with

device.RenderState.CullMode = Cull.CounterClockwise;

If you do these two step you should get a normal-looking spinning cube that only shows the faces that are visible to the camera and not obstructed by the rest of the cube.

Without making these changes what you get is an attempt to draw the cube without any knowlege of what faces/colours should be on top of each other. If you run it again without culling turned on you'll notice that the last colours defined in the function that
generates the cube are the colours that are on top and hence drawn most often, and the first colours are generally obscured (that is, you get more purple and red than aqua and yellow).

In case anybody is interested, here is my modified code for constructing the triangles so that they obey the clockwise winding rule.