Exegesis
Exegesis

Reputation: 1088

OpenGL glBegin vs Vertex Buffer Arrays VBO

I want to make an OpenGL game but now realize that what I've learned in school -> draw objects directly by glBegin/glEnd -> is old-school and bad. Readings on the internet I see that Vertex Buffer Objects and GLSL is the "proper" method for 3d programming.

1) Should I use OpenGL's glDrawArrays or glDrawElements?

2) For a game with many entities/grounds/objects, must the render function be many glDrawArrays():

foreach(entity in entities):
    glDrawArrays(entitiy->arrayFromMesh()) //Where we get an array of the mesh vertex points

or only one glDrawArrays() that encapsulates every entity:

glDrawArrays(map->arrayFromAllMeshes())

3) Does every graphics layer (such as DirectX) now standardize Vertex Buffer Objects?

Upvotes: 0

Views: 2603

Answers (1)

Tim
Tim

Reputation: 35943

1) Should I use OpenGL's glDrawArrays or glDrawElements?

This depends on what your source data looks like. glDrawArrays is a little less complex, as you just have to draw a stream of vertices, but glDrawElements is useful in a situation where you have many vertices which are shared by several triangles. If you're just drawing sprites, then glDrawArrays is probably the simplest, but glDrawElements is useful for huge complex meshes where you want to save buffer space.

2) For a game with many entities/grounds/objects, must the render function be many glDrawArrays() or only one glDrawArrays() that encapsulates every entity:

Again this is somewhat optional, but note that you can't change program state in the middle of a drawarrays call. So that means that any two objects which need different state (different textures, different shaders, different blend settings), must have a separate draw call. However it can sometimes be helpful for performance to group as many similar things into a single draw call as you can.

3) Does every graphics layer (such as DirectX) now standardize Vertex Buffer Objects?

DirectX does have a similar concept, yes.

Upvotes: 3

Related Questions