glDrawElements vs. glVertex3f

Started by
12 comments, last by _the_phantom_ 19 years, 9 months ago
Hi all, I have an opengl book that has an example of small game engine, and it is using glVertex3f() to draw all triangles. However, in one of the chapters, it says that glDrawElements() is more efficient and powerful. So which one is more efficient? Assume that glVertex3f() is drawing from vertex array. Thanks, Andy
Advertisement
Using glVertex*() functions is called immediate mode and is NOT a good idea for rendering lots of stuff.
glDrawElements (and other vertex array functions) really are faster and it's a good idea to get used to using vertex arrays.
For even better performance, you could try Vertex Buffer Objects (if your card supports them).

Vertex arrays (glDrawElements) will always be faster to immediate mode (glVertex3f).

your book probably explains why, might want to take a look at VBO's too.
glDrawElements will be faster on pretty much any hardware in existence.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Thank you for all of your replies!!! You guys are good.

One more question, when I use glDrawElements(), do I need glBegin() and glEnd()?

Andy
Nope.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
But then when I take away those two lines, my program crashes, once I put them back, it runs fine..???

Thanks,

Andy
Post code. You're probably messing something else up.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
your indicies are incorrect, or something similar, lemme guess, its an access violation right? you or openGL is trying to read outside the bounds of your arrays, which is bad, hence the violation, just make sure you pass the right sizes and stuff, and make sure your indicies (if ur using them) dont point to vertices outside of the bounds of the arrays ur using (ie: you have a vertex array, and a texture coordinate array, both have 256 elements, if you have one of ur indices asking for element 257, (or even 256 since its base 0) you should get an access violation, hope that helps
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
Ademan555 you are good!!! yes, I have that problem, thanks a lot.

Andy

This topic is closed to new replies.

Advertisement