1
\$\begingroup\$

I've just now started learning OpenGL and I'm getting very overwhelmed and confused with some things. I don't want to permaturely optimize things, but I also don't make decisions about things I still don't fully understand.

Question 1: I know that immediate mode compared to the use of VBOs in OpenGL is primitive and slow, but how much does it really matter for a 2D game, unless I start rendering tens of thousands sprites? At which point does it really justify the hassle of having to go through all that tedious process of the modern OpenGL? (I know modern OpenGL is a better practice, I am just legitimately curious!)

Question 2: I'm making a 2D game, it is going to implement particles, a few sprites, raycasted shadows and some blending tricks. My question is, do I keep one VAO and VBO for each Sprite, or do I create all the sprites in one single VBO / VAO? If so, how do I do that, how should my code be structured? I'm very confused as to how I should batch the draw calls.

Question 3: Is it significantly expensive to swap shaders? How do I handle multiple shaders? I thought about categorizing the objects and join the ones that have the same shader together for drawing, so I don't have to switch shaders as much, but I wasn't sure if it was worth the hassle.

\$\endgroup\$

closed as off-topic by Kromster, Josh Feb 26 '15 at 19:48

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about "how to get started," "what to learn next," or "which technology to use" are discussion-oriented questions which involve answers that are either based on opinion, or which are all equally valid. Those kinds of questions are outside the scope of this site. Visit our help center for more information." – Kromster, Josh
If this question can be reworded to fit the rules in the help center, please edit the question.

3
\$\begingroup\$

Question 1:

As always, it depends, and on many factors. Not only it depends on how much stuff you're drawing, but also on the particular video card, drivers and OS.

In general, the old way of doing things (immediate mode and fixed pipeline) will probably be fast enough for your needs.

However, you should probably consider doing things the modern way (vertex buffers and shaders). Not only you will find it's not a hassle at all, and the "tedious process" is just a different way of doing things, but you'll also find that the modern way of doing things makes more sense, and will probably help you organize your code much easier.

Question 2:

Each one of those options makes sense, and has different advantages and disadvantages. For what you want to do, probably either will work fine, so you should probably do what makes more sense to you.

Usually, updating VBOs takes time, so you should probably not share VBOs between things that change a lot (like particles or shadows) and things that don't (GUI and static parts of the map). However, switching between VBOs also takes time, so you shouldn't go overkill and have one VBO per object. There are thousands of ways to organize your code, and none is perfect, so you should probably do what makes the most sense to you.

Question 3

Switching shaders is not such a big deal. As long as you're not compiling them on each frame, you can have hundreds of different shaders and switch them as you switch objects.

In my experience, switching shaders is pretty similar to switching textures or VBOs. Once again, do what makes the most sense to you, and only optimize when you find and measure bottlenecks.

You'll be surprised how fast modern video cards are, so for the type of game you're describing, you'll most likely have no performance problems, unless you do something extremely wrong, and maybe not even then.

You should usually prefer writing code in the way that makes most sense to you first, and worry about optimizations later.

\$\endgroup\$
  • \$\begingroup\$ I wonder what was wrong with my answer so it deserved a downvote... \$\endgroup\$ – Panda Pajama Feb 26 '15 at 6:05
  • \$\begingroup\$ Don't know, maybe it is because you are answering offtopic question .. \$\endgroup\$ – Kromster Feb 26 '15 at 7:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.