I need to draw lots of cubes and so I’m using VBOs.
I need them to have vertexes(obviously), normals and textures, so I’ve defined all the data like this:
GLfloat cubeVertexData[] =
{
1.0f, 1.0f, 1.0f, // 0
0.0f, 1.0f, 1.0f, // 1
0.0f, 0.0f, 1.0f, // 2
1.0f, 0.0f, 1.0f, // 3
1.0f, 0.0f, 0.0f, // 4
1.0f, 1.0f, 0.0f, // 5
0.0f, 1.0f, 0.0f, // 6
0.0f, 0.0f, 0.0f // 7
};
GLfloat cubeNormalData[] =
{
0.0f, 0.0f, 1.0f, // Front
1.0f, 0.0f, 0.0f, // Right
0.0f, 1.0f, 0.0f, // Top
-1.0f, 0.0f, 0.0f, // Left
0.0f, -1.0f, 0.0f, // Bottom
0.0f, 0.0f, -1.0f // Back
};
GLfloat cubeTextureData[] =
{
0.0f, 0.0f, // 0
1.0f, 0.0f, // 1
1.0f, 1.0f, // 2
0.0f, 1.0f // 3
};
Now the problem is I’m not sure how to go about indexing. At the moment I have just stuck everything in one index like this which I imagine is wrong.
GLubyte cubeIndex[] =
{
// Vertex
0,1,2, 2,3,0, // Front
0,3,4, 4,5,0, // Right
0,5,6, 6,1,0, // Top
1,6,7, 7,2,1, // Left
7,4,3, 3,2,7, // Bottom
4,7,6, 6,5,4, // Back
0,0,0, 0,0,0, // Front
1,1,1, 1,1,1, // Right
2,2,2, 2,2,2, // Top
3,3,3, 3,3,3, // Left
4,4,4, 4,4,4, // Bottom
5,5,5, 5,5,5, // Back
0,1,2, 2,3,0, // Front
0,1,2, 2,3,0, // Right
0,1,2, 2,3,0, // Top
0,1,2, 2,3,0, // Left
0,1,2, 2,3,0, // Bottom
0,1,2, 2,3,0 // Back
};
What do I need to do and then which arguments do I put in glDrawElements?
Any help is much appreciated.
Thanks,
Rowan.