OpenGL: Is there a better/faster way to draw big 2D backgrounds?

Started by
5 comments, last by ionosphere 14 years, 4 months ago
Currently, I have several backgrounds (let's say the size can be 640 x 480 or 800 x 600 or such) in a 2D game and I draw these backgrounds by simply putting these backgrounds as textures on 2D planes (using GL_QUADS) in orthogonal views. It works fine. I can rotate, scale, and apply alpha transparency without any problem. (I also do not clear the buffer because the background will cover the old frame anyway) However, I am curious whether there is a faster/better way in OpenGL for this, as it seems that the game's FPS drop a bit on older machines. Because I only need to draw 2D backgrounds (that may occasionally require scale, rotate, and transparency), I am wondering whether is this the best way we can do with OpenGL to draw things for just 2D game or are there better ways to skip all the 3D pipelines stuff completely for better performance? If you know something I do not, please share. Thank you.
Advertisement
Drawing the background with a quad should be pretty fast, the pipeline overhead is not much. If you want, you can directly write pixels to the framebuffer using glDrawPixels ( http://www.opengl.org/sdk/docs/man/xhtml/glDrawPixels.xml ), but I do not think this will be much faster (if at all).

If you are drawing a lot of things on top of the background, try rendering the scene first with depth 0, and then drawing the background as a quad with depth 1 and the depth test enabled. This way, any pixels where there was something on top of the background will fail the depth test and will not need to be drawn, which could improve performance if not much of the background is visible.
glDrawPixels WILL be slower; texturing is the fastest way to get the image onto the screen.
Quote:Original post by terra0nova
Drawing the background with a quad should be pretty fast, the pipeline overhead is not much. If you want, you can directly write pixels to the framebuffer using glDrawPixels ( http://www.opengl.org/sdk/docs/man/xhtml/glDrawPixels.xml ), but I do not think this will be much faster (if at all).
It will in general be much, much slower on modern cards.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Quote:Original post by terra0nova
...
If you are drawing a lot of things on top of the background, try rendering the scene first with depth 0, and then drawing the background as a quad with depth 1 and the depth test enabled. This way, any pixels where there was something on top of the background will fail the depth test and will not need to be drawn, which could improve performance if not much of the background is visible.


If your foreground objects have transparency, this will cause incorrect rendering wherever the foreground has transparency.

Also, OP: What does it mean when the background has transparency? What do you want to show up behind it? The previous frame? A black buffer? Random garbage?

If you want the previous frame, be aware that some video card drivers will use single, double, or triple buffering regardless of what your application asks for. That means that there'll be a variable delay.
for the fastest method go

draw scene objects
draw background
draw translucent things

<-- the reason why u draw the background afterwards is cause some of the pixels will be covered up by the foreground objects thus youre not drawing twice in the same area
Quote:Original post by nagromo

Also, OP: What does it mean when the background has transparency? What do you want to show up behind it? The previous frame? A black buffer? Random garbage?

If you want the previous frame, be aware that some video card drivers will use single, double, or triple buffering regardless of what your application asks for. That means that there'll be a variable delay.


Occasionally I may want to use previous frames for pseudo motion blur effects, so according to your post, this method may not work with some Graphics Card, right? So are there any work around?

This topic is closed to new replies.

Advertisement