Having trouble getting triangles with glDrawElements.
Question 1) What is the max size I can pass it? It seems that even with GL_UNSIGNED_INT I can’t go much higher than 32k without it crashing. I reach no such limit with glDrawArrays.
Question 2) When I call it with GL_POINTS the points are in the right places. But GL_TRIANGLES gives me bizarre triangles. It looks like the indeces aren’t correct. I have verified the data type for indeces. I’ve tried different types of arrays. Nothing works. It’s giving me random looking triangles on correct points.
Here is the code that correctly renders the first 3000 points and proves my indexing is right (BTW I’m using std::vectors for my arrays, therefore: continuous memory)
glBegin(GL_TRIANGLES);
for(int i=0; i<3000; i++)
{
int idx = mTriIdxGrid[i];
float* p = &mPointGrid [idx];
float* n = &mNormalGrid[idx];
glNormal3fv(n);
glVertex3fv(p);
}
glEnd();
I thought that the following should do the same thing… but it doesn’t… I get messed up triangles why?:
glEnableClientState( GL_NORMAL_ARRAY);
glEnableClientState( GL_VERTEX_ARRAY);
glVertexPointer( 3, GL_FLOAT, 0, &mPointGrid[0] );
glNormalPointer( GL_FLOAT, 0, &mNormalGrid[0] );
glDrawElements ( GL_TRIANGLES, 3000, GL_UNSIGNED_INT, &mTriIdxGrid[0] );
glDisableClientState( GL_NORMAL_ARRAY); GL_ASSERT;
glDisableClientState( GL_VERTEX_ARRAY);
Since I’ve seen people make mistakes with index data type I did this sort of thing, it’s exactly the same:
GLushort shorts[3000];
for(int i=0; i<3000; i++)
{
assert( mTriIdxGrid[i] < 0xFFFF );
shorts[i] = mTriIdxGrid[i];
}
glEnableClientState( GL_NORMAL_ARRAY);
glEnableClientState( GL_VERTEX_ARRAY);
glVertexPointer( 3, GL_FLOAT, 0, &mPointGrid[0] );
glNormalPointer( GL_FLOAT, 0, &mNormalGrid[0] );
glDrawElements ( GL_TRIANGLES, 3000, GL_UNSIGNED_SHORT, shorts );
glDisableClientState( GL_NORMAL_ARRAY); GL_ASSERT;
glDisableClientState( GL_VERTEX_ARRAY);
I know I’m being a retard I just can’t see where…