Opengl 2D Performance Tips

I am currently developing a Touhou-esque style shooter game. The screen will be completely filled with bullets (so instancing is what I want here), but I want this to work on older hardware, so I am doing something along those lines for now, no colors, textures, and so on until I figure it 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();
}

      

Since I want this to work on older hardware, I try to avoid shaders and whatnot. Setting up there doesn't allow me about 80 polygons. I'm looking to get at least a few hundred from this. info

is a framework that has all the benefits of rendering, nothing special to it, apart from a few vectors.

I'm new to OpenGL, but I've at least heard and tried everything that can be done, not to say that I'm good at it. This game is a 2D game, I switched from SDL to Opengl because it would facilitate some more favorable effects. Obviously SDL works differently, but I've never had this problem using it.

It boils down to this, I am clearly doing something wrong here, so how can I properly implement instancing for old hardware (OpenGL 1.x)? Also, give me some tips for improving performance.

+3


source to share


1 answer


Also, give me some tips for improving performance.

If you are going to use sprites ....

  • Load all the sprites into one huge texture. If they don't fit, use multiple textures, but keep the number of textures low - to avoid switching textures.
  • Switch textures and change OpenGL state as rarely as possible. Ideally, you should set the texture once and do whatever you can.
  • Use textured fonts for text. The FTGL font may sound nice, but it can hit complex fonts very hard.
  • Avoid alpha blending whenever possible and use alpha testing.
  • When alpha blending, always use alpha testing to reduce the number of pixels you paint. When your texture has many pixels with alpha == 0, cut them out with an alpha test.
  • Reduce the number of very large sprites. Huge screen-aligned / pixel-aligned ellipse (1024 * 1024) will reduce FPS even on very good hardware.
  • Do not use textures with dimensions other than 2. They (usually) produce huge performance degradation on some ATI cards.

glTranslatef



For a 2D sprite (this important) game, you can avoid matrices altogether (except maybe camera / projection matrices). I don't think matrices will be very useful for you in a 2D game.

In a 2d game, your main bottleneck will be the GPU transfer rate - the transfer of 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 are going to use vector graphics (see area2048 ( youtube ) or rez ), which does not use textures, then most of the recommendations above will not apply and such a game will not be very different from a 3D game. In this case, it would be wise to use vertex arrays, vertex buffer objects, or display lists (whichever is available) and use a matrix function, because your bottleneck will be vertex handling. You will still have to minimize the number of state switches.

+9


source







All Articles