OpenGL Madness
- 2005-04-04
- Trackback URL
- General
Arg. It’s 7:20am and I’m still awake. I spent the better part of the night trying to texture these spheres for my COMP 259 homework. Just as I was almost done, insanity set in: the spheres were rendering with their textures inside out. After much googling, I found some post from 2001 on some Apple developer site, but the responses didn’t resolve the question. I have come to the conclusion that gluSphere must be tesselating a sphere into triangles with a clock-wise orientation, which is the opposite of what the rest of OpenGL does. This might seem inconsequential to most of my readers, but it means that instead of showing the front of the sphere when you’re looking at the front, you instead see the back. I’m not sure if this is intentional or some obscure bug or what. For now though, telling OpenGL that clockwise faces are on the front seems to have solved the problem.
The thing that pisses me off the most is that I can’t find this really mentioned anywhere on the web or Usenet. The man page in gluSphere does mention that the normals of the generated sphere tesselation will point inwards unless a different setting is used (which doesn’t change the effects though), but never once does it say to change the face culling if you want it to work with the rest of OpenGL (and who doesn’t want that?). Strangely, the man page for glutSolidTeapot explicitly says you have to do the following:
BUGS
The teapot is greatly over-tesselated; it renders way too slow.
OpenGL's default glFrontFace state assumes that front facing polygons
(for the purpose of face culling) have vertices that wind counter
clockwise when projected into window space. This teapot is rendered
with its front facing polygon vertices winding clockwise. For OpenGL's
default back face culling to work, you should use:
glFrontFace(GL_CW);
glutSolidTeapot(size);
glFrontFace(GL_CCW);
Both these bugs reflect issues in the original aux toolkit's teapot
rendering routines (GLUT used the same teapot rendering routine).
I honestly wonder why this is the case. There must be some sort of story based on backwards compatability or something.