I’m using VBO, so, no glBegin(). How do I set a normal to each face of my object?
I got 2 arrays. 1 for my vertex_positions, and another one for my index. Can I include my normals inside my vertex_positions array?
I got this, right now, but don’t know if its working:
static GLfloat vertices[cubeMatrixSize][9] =
{// R G B X Y Z NORMALS
{1.0, 0.0, 0.0, -1.0, -1.0, -1.0, 0, -1, 0}, // 0 -- REDs
{0.0, 1.0, 0.0, 1.0, -1.0, -1.0, 1, 0, 0},// 1 -- GREEN
{0.0, 0.0, 1.0, 1.0, 1.0, -1.0, 1, 0, 0},// 2 -- BLUE
{1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 0, 1, 0},// 3 -- WHITE
{0.5, 0.5, 0.5, -1.0, -1.0, 1.0, 0, 0, 1},// 4 -- GRAY
{1.0, 1.0, 0.0, 1.0, -1.0, 1.0, 0, 0, 1},// 5 -- YELLOW
{1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0, 1, 0},// 6 -- MAGENT
{0.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1, 0, 0}// 7 -- CYAN
};
GLubyte indices[12][3] = {
{0, 4, 7 },
{0, 7, 3 },
{5, 7, 4 },
{6, 7, 5 },
{3, 7, 6 },
{6, 2, 3 },
{6, 5, 1 },
{6, 1, 2 },
{3, 1, 0 },
{3, 2, 1 },
{5, 4, 0 },
{0, 1, 5 }
};
The problem is. How do the opengl know which normal belongs to which triangle?
How do I say that the vector in the first line (0, -1, 0) belongs to the first face? and not to another one?
(reading the RedBook and it doesn’t explain it (as far as I’ve read it)).
Will I need to create another array with the same size of the INDICES array and the first vector will be the normal of the first triangle in INDICES array, the second vector the second in INDICES until it’s over? Is that how it works?
thanks!