3

I have been looping through a game entity list and calling a virtual Render fn that uses: glBegin/glEnd. Recently I've learned that Vertex-Buffer-Arrays are the way to go (especially for ios/Android).

  • When I create a new entity into the world, I merely have to bind the entity's VAO to VBO, set its VAO id. Thus if I have N entities, I have N VAO/VBO's?
  • On the render function I don't need to re-bind anything, only call "glDrawArray/Element"?
  • Can I use both glBegin/glEnd-style OpenGL as well as VAO/VBO's in the render fn?
  • It seems that OpenGL hates OOP, but I need OOP for game programming... how do I solve this paradox?
4

1 回答 1

7

Thus if I have N entities, I have N VAO/VBO's?

In decent game engine, if you have a thousands of objects with the same geometry (say, discarded bullet cases or something), there's only one instance (VAO/VBO/whatever) of that geometry/mesh loaded into game engine. Object and mesh used by that object are two different things. Multiple objects can use same mesh instance.

Can I use both glBegin/glEnd-style OpenGL as well as VAO/VBO's in the render fn?

Yes, although some people insist that because OpenGL 3/4 is available, you should avoid glBegin/glEnd and similar old-style functions. Still, it is up to you.

It seems that OpenGL hates OOP, but I need OOP for game programming... how do I solve this paradox?

It doesn't. Technically, integer IDs used by OpenGL are objects and function that operate on them are methods of those objects. It isn't that hard to wrap those integer ids into structures/classes, anyway.

On another hand, you don't have to use OOP. (opinion) Nowadays "OOP" is frequently overused. If you can solve your problem using simple structures/arrays, and the code will be readable/easy to maintain, there's no reason to go nuts and design full-blown object hierarchy for everything.

于 2013-08-20T05:07:17.593 回答