3
votes

I'm currently developing a Touhou-esque bullet hell shooter game. The screen will be absolutely filled with bullets (so instancing is what I want here), but I want this to work on older hardware, so I'm doing something along the lines of this at the moment, there are not colors, textures, etc. yet until I figure this out.

glVertexPointer(3, GL_FLOAT, 0, SQUARE_VERTICES);
for (int i = 0; i < info.centers.size(); i += 3) {
    glPushMatrix();
    glTranslatef(info.centers.get(i), info.centers.get(i + 1), info.centers.get(i + 2));
    glScalef(info.sizes.get(i), info.sizes.get(i + 1), info.sizes.get(i + 2));
    glDrawElements(GL_QUADS, 4, GL_UNSIGNED_SHORT, SQUARE_INDICES);
    glPopMatrix();
}

Because I want this to work on old hardware I'm trying to avoid shaders and whatnot. The setup up there fails me on about 80 polygons. I'm looking to get at least a few hundred out of this. info is a struct which has all the goodies for rendering, nothing much to it besides a few vectors.

I'm pretty new to OpenGL, but I at least heard and tried out everything that can be done, not saying I'm good with it at all though. This game is a 2D game, I switched from SDL to Opengl because it would make for some fancier effects easier. Obviously SDL works differently, but I never had this problem using it.

It boils down to this, I'm clearly doing something wrong here, so how can I implement instancing for old hardware (OpenGL 1.x) correctly? Also, give me any tips for increasing performance.

1
Have you done any profiling using a tool like GDebugger? That will tell you the bottleneck.Pubby
Use as few draw calls as possible, try to put everything in one VA (do all the translations etc yourself on the CPU side).harold

1 Answers

9
votes

Also, give me any tips for increasing performance.

If you're going to use sprites....

  1. Load all sprites into single huge texture. If they don't fit, use several textures, but keep number of textures low - to avoid texture switching.
  2. Switch textures and change OpenGL state as infrequently as possible. Ideally, you should set texture once, and draw everything you can with it.
  3. Use texture fonts for text. FTGL font might look nice, but it can hit performance very hard with complex fonts.
  4. Avoid alpha-blending when possible and use alpha-testing.
  5. When alpha-blending, always use alpha-testing to reduce number of pixels you draw. When your texture has many pixels with alpha==0, cut them out with alpha-test.
  6. Reduce number of very big sprites. Huge screen-aligned/pixel-aligne sprite (1024*1024) will drop FPS even on very good hardware.
  7. Don't use non-power-of-2 sized textures. They (used to) produce huge performance drop on certain ATI cards.

glTranslatef

For 2D sprite-based(that's important) game you could avoid matrices completely (with exception of camera/projection matrices, perhaps). I don't think that matrices will benefit you very much with 2D game.

With 2d game your main bottleneck will be GPU memory transfer speed - transferring data from texture to screen. So "use as little draw calls" and "put everything in VA" won't help you - you can kill performance with one sprite.

However, if you're going to use vector graphics (see area2048(youtube) or rez) that does not use textures, then most of the advice above will not apply, and such game won't be very different from 3d game. In this case it'll be reasonable to use vertex arrays, vertex buffer objects or display lists (depends on what is available) and utilize matrix function - because your bottleneck will be vertex processing. You'll still have to minimize number of state switches.