View Full Version : Problems with simple cube and normals

01-05-2011, 10:16 AM

I have a problem with specifying the normals for a simple cube.
My vertices look like this:

std::vector<GLfloat> vertices =
0.0f,0.0f,0.0f, 1.0f,0.0f,0.0f, 1.0f,1.0f,0.0f, 0.0f,1.0f,0.0f, //front
0.0f,0.0f,1.0f, 1.0f,0.0f,1.0f, 1.0f,1.0f,1.0f, 0.0f,1.0f,1.0f, //back
0.0f,0.0f,0.0f, 0.0f,0.0f,1.0f, 0.0f,1.0f,1.0f, 0.0f,1.0f,0.0f, //left
1.0f,0.0f,0.0f, 1.0f,0.0f,1.0f, 1.0f,1.0f,1.0f, 1.0f,1.0f,0.0f, //right
0.0f,0.0f,0.0f, 1.0f,0.0f,0.0f, 1.0f,0.0f,1.0f, 0.0f,0.0f,1.0f, //bottom
0.0f,1.0f,0.0f, 1.0f,1.0f,0.0f, 1.0f,1.0f,1.0f, 0.0f,1.0f,1.0f //top

and my normals:

std::vector<GLfloat> normals =
0.0f,0.0f,1.0f, 0.0f,0.0f,1.0f, 0.0f,0.0f,1.0f, 0.0f,0.0f,1.0f,
0.0f,0.0f,-1.0f, 0.0f,0.0f,-1.0f, 0.0f,0.0f,-1.0f, 0.0f,0.0f,-1.0f,
-1.0f,0.0f,0.0f, -1.0f,0.0f,0.0f, -1.0f,0.0f,0.0f, -1.0f,0.0f,0.0f,
1.0f,0.0f,0.0f, 1.0f,0.0f,0.0f, 1.0f,0.0f,0.0f, 1.0f,0.0f,0.0f,
0.0f,-1.0f,0.0f, 0.0f,-1.0f,0.0f, 0.0f,-1.0f,0.0f, 0.0f,-1.0f,0.0f,
0.0f,1.0f,0.0f, 0.0f,1.0f,0.0f, 0.0f,1.0f,0.0f, 0.0f,1.0f,0.0f


Everything is packed in a vbo and is drawn by
glDrawArrays(GL_QUADS,0,24). The cube looks alright, but the left and right
side stays dark. The same code for drawing works without problems when i
import obj-files from blender. So there must be something wrong
with the normals. Any ideas?

carsten neumann
01-05-2011, 10:24 AM
OpenGL uses a right handed coordinate system (at least for the fixed function pipeline), so if x points to the right, y up, then z points towards you - in your image z points away from you.
The result is that you specify the left and right sides with different winding and you end up looking at the back faces.

01-05-2011, 10:36 AM
God damm. I could cry. Your are right, error is fixed. Cost me
3 hours ;)