problem w/ glDrawElements

ok, when i have code that does this:


everything works fine (this is simplified, because i have stuff in classes, and i dont want to paste in all my class defenitions, etc)

however, when i do this:


nothing is displayed. these are both being done in “for” loops, and my open gl book says that drawelements sets color, normal, texture, etc “indeterminate” it doesnt say what about them is indeterminate (ie, are the actual values messed up, just the pointers, what?). i tried reseting the vertex and normal pointers after each drawelements call, but it didnt work. also, i tried drawelements between and not between glbegin/end statements, and it didnt work either…

thanks for any help…

The second parameter to glDrawElements is the number of elements to render. If your two code snippets are supposed to be equivalent, the second call should be:

glDrawElements(GL_TRIANGLES, 1, GL_INT, vertices);

Hope that helps.

hmm, according to the red book, the “count” should corespond to the number of glArrayElement calls, which would be 3 (one for each vertex, not each triangle). i tried using 1 anyway, and it still didnt work…

Are you sure that your indices are defined in GL_INT format?

If that doesn’t solve it, try this. Make a conditional statement for drawing that looks like this:

Do glBegin/end for glArrayElement drawing
Do glDrawElements call

Now, once you set that up, you should be able to switch back and forth at runtime by setting this variable in the debugger. If the glDrawElements call doesn’t draw anything still, then you should check your glErrors for a problem.

Oh, and by the way, glDrawElements should not come between glBegin and glEnd.

well your naming convention is wrong

glVertexPointer(… vertices )
glDrawElements( … indices )
glArrayElement( indicenumber )

ok, i realise that technically, verticies is not the correct naming convention, but you have to trust me that it holds the correct value (hey, the preceding working code uses the same variables…).

the reason for the goofy naming convention is that i am actually using a triangle class, and when i originally wrote it, i wasnt using vertex arrays, so “verticies” was, in fact, correct. i have no intention to debug the name change. this isnt even going to go into my finished project, its just a test of some various things…

ok, i figured it out. had to check the errors, but anyway…

i was passing a GLint as “type”, but the indicies had to be unsigned.

everything works now. plus, i learned how to use the gl error messages. yay!

it should work with GL_INT
GLint indices[] = { … };
glDrawElements( …, GL_INT )
if it doesnt then its a bug i believe
though most ppl use GL_UNSIGNED_SHORT (usually fastest) or GL_UNSIGNED_INT cause u get double the number of indices than the signed data type

well, the error i got was “invalad enum type” and when i looked it up in the blue book, there were only three valid types: unsigned byte, unsigned short, and unsigned int…

i guess i should have been paying more attention when i looked it up the first time : )

whoops my bad i checked the red book and youre correct only ubyte uint + ushort are allowed, sorry about that