PDA

View Full Version : glDrawElements and interleaved data



Malachi
02-24-2005, 07:44 AM
I am having problems getting glDrawElements to work with interleaved data. Here is the simple example I'm trying to get to work. The data is packed with two tex coords and three vert positions for each vertex. When I run this example I don't see anything.

static GLushort g_cubeIndicies[] =
{
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 14, 15,
16, 17, 18, 19,
20, 21, 22, 23
};

float g_cubeVertices[] =
{
0.0f,0.0f, -1.0f,-1.0f, 1.0f,
1.0f,0.0f, 1.0f,-1.0f, 1.0f,
1.0f,1.0f, 1.0f, 1.0f, 1.0f,
0.0f,1.0f, -1.0f, 1.0f, 1.0f,

1.0f,0.0f, -1.0f,-1.0f,-1.0f,
1.0f,1.0f, -1.0f, 1.0f,-1.0f,
0.0f,1.0f, 1.0f, 1.0f,-1.0f,
0.0f,0.0f, 1.0f,-1.0f,-1.0f,

0.0f,1.0f, -1.0f, 1.0f,-1.0f,
0.0f,0.0f, -1.0f, 1.0f, 1.0f,
1.0f,0.0f, 1.0f, 1.0f, 1.0f,
1.0f,1.0f, 1.0f, 1.0f,-1.0f,

1.0f,1.0f, -1.0f,-1.0f,-1.0f,
0.0f,1.0f, 1.0f,-1.0f,-1.0f,
0.0f,0.0f, 1.0f,-1.0f, 1.0f,
1.0f,0.0f, -1.0f,-1.0f, 1.0f,

1.0f,0.0f, 1.0f,-1.0f,-1.0f,
1.0f,1.0f, 1.0f, 1.0f,-1.0f,
0.0f,1.0f, 1.0f, 1.0f, 1.0f,
0.0f,0.0f, 1.0f,-1.0f, 1.0f,

0.0f,0.0f, -1.0f,-1.0f,-1.0f,
1.0f,0.0f, -1.0f,-1.0f, 1.0f,
1.0f,1.0f, -1.0f, 1.0f, 1.0f,
0.0f,1.0f, -1.0f, 1.0f,-1.0f
};

...

glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glEnableClientState( GL_VERTEX_ARRAY );

glBindTexture( GL_TEXTURE_2D, g_textureID );


glTexCoordPointer(2, GL_FLOAT, 5*sizeof(float), &g_cubeVertices[0]);
glVertexPointer(3, GL_FLOAT, 5*sizeof(float), &g_cubeVertices[2]);

glDrawElements(GL_QUADS, 3, GL_UNSIGNED_SHORT, &g_cubeIndicies[0]);


glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glDisableClientState( GL_VERTEX_ARRAY );When I replace the glDrawElements call with the following glDrawArrays call, I can see the textured cube just fine.


glDrawArrays(GL_QUADS, 0, 24);I would like to be able to use glDrawElements for speed and flexibility reasons.
Thank you,
Malachi

Relic
02-24-2005, 08:48 AM
Piece of cake: glDrawElements gets the count of indices as second parameter. You put 3 that's not enough for even a single quad. You wanted 24 indices there.
(glDrawElements is probably not helpful for this array of indices without any duplicate index in it.)