PDA

View Full Version : problem w/ glDrawElements



Spiral Man
09-18-2001, 06:04 PM
ok, when i have code that does this:

glBegin(GL_TRIANGLES);
glArrayElement(verticies[0]);
glArrayElement(verticies[1]);
glArrayElement(verticies[2]);
glEnd();

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:

glDrawElements(GL_TRIANGLES,3,GL_INT,verticies);

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...

ffish
09-18-2001, 06:51 PM
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.

Spiral Man
09-19-2001, 02:37 PM
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....

Korval
09-19-2001, 03:26 PM
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:

if(some_boolean_variable)
{
Do glBegin/end for glArrayElement drawing
}
else
{
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.

zed
09-19-2001, 04:09 PM
well your naming convention is wrong

glVertexPointer(... vertices )
+
glDrawElements( ... indices )
glArrayElement( indicenumber )

Spiral Man
09-19-2001, 06:57 PM
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...

Spiral Man
09-20-2001, 02:42 PM
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!

zed
09-20-2001, 04:56 PM
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

Spiral Man
09-20-2001, 06:16 PM
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 : )

zed
09-21-2001, 01:07 AM
whoops my bad i checked the red book and youre correct only ubyte uint + ushort are allowed, sorry about that