In an effort to learn OpenGL as well as some basic AI, I am trying to create a Rubik’s Cube solver. This is strictly an educational exercise, so I chose to use C# and the TAO framework so that I could concentrate on the object oriented design without worrying about memory or the nitty gritty WIN32 details.
When I render the Rubik’s Cube using GL_QUADS, it works great. But when I try to modify my code so that it uses GL_TRIANGLE_STRIP I run in to some problems.
The problem is visible in the following screen shots … in these shots, I am only rendering the top/front/left corner of the cube.
http://members.shaw.ca/afoat/problem.jpg
The weird thing is that this problem only appears on blue squares that are next to orange squares
http://members.shaw.ca/afoat/problem1.jpg
- All drawn with GL_QUADS - works great
- Yellow = GL_QUADS, Orange = GL_TRIANGLE_STRIP - works great
- Blue = GL_TRIANGLE_STRIP - works great
- Both = GL_TRIANGLE_STRIP
- Yellow = GL_QUADS, Blue = GL_TRIANGLE_STRIP
The only difference between 3 and 4 is that I removed the commented portion of code that draws the orange face.
Here is the code for the orange and blue triangle strips
//Orange List
s_FrontList = Gl.glGenLists(6);
Gl.glNewList(s_FrontList, Gl.GL_COMPILE);
Gl.glBegin(Gl.GL_TRIANGLE_STRIP);
Gl.glNormal3f(0.0f, 0.0f, 1.0f);
Gl.glTexCoord2f(0f, 1f); Gl.glVertex3f(-1f, 1f, 1f);
Gl.glTexCoord2f(0f, 0f); Gl.glVertex3f(-1f, -1f, 1f);
Gl.glTexCoord2f(1f, 0f); Gl.glVertex3f( 1f, -1f, 1f);
Gl.glTexCoord2f(1f, 1f); Gl.glVertex3f( 1f, 1f, 1f);
Gl.glEnd();
Gl.glEndList();
//Blue List
s_TopList = s_FrontList + 1;
Gl.glNewList(s_TopList, Gl.GL_COMPILE);
Gl.glBegin(Gl.GL_TRIANGLE_STRIP);
Gl.glNormal3f(0.0f, 1.0f, 0.0f);
Gl.glTexCoord2f(0f, 0f); Gl.glVertex3f(-1f, 1f, -1f);
Gl.glTexCoord2f(0f, 1f); Gl.glVertex3f(-1f, 1f, 1f);
Gl.glTexCoord2f(1f, 1f); Gl.glVertex3f( 1f, 1f, 1f);
Gl.glTexCoord2f(1f, 0f); Gl.glVertex3f( 1f, 1f, -1f);
Gl.glEnd();
Gl.glEndList();
...
Gl.glCallList(s_FrontList);
Gl.glCallList(s_TopList);
Even though these two faces are drawn within their own glBegin/glEnd blocks, do neighboring triangle strips share verticies?
I’m not sure if it matters, but the texture is a mostly transparent PNG with a black border … this is used to separate squares on a face to give it that Rubik’s-y feel.
Can someone please explain what I might be missing?