You don't need OpenGL/Direct3D for 2D games

I’ve seen many people ask about using OpenGL with 2D games and I felt
compelled to say something. Hopefully this will help some of those people.

One thing I discovered when using OpenGL in 2D games is it isn’t necessary
and it severely limits what you can do in your 2D game. Once you load all of
those images onto the graphics card you cannot read and write pixels. If you
don’t have that capability you can’t have pulsing creatures and weapons
(like Baldurs Gate).

Recently I invented a method of drawing which lets you make use of almost
any effect in software mode without affecting your frame rate.
I call it the Special Surface Method. I’m sure the big companies used it in
the days of yore.

Special Surface Method:

I store all of my animations in ram (or system memory) and use a single
surface (from now I’ll call it S.S. short for special surface) to draw to
the screen.

Each time the animation increments I copy a frame of the animation to the
S.S. with the lighting effect switched on. As this is done once per
animation increment it does not affect the game’s frame rate. From then on I
draw S.S. to the screen using a standard blitter which is plenty fast.

Drawbacks of the Special Surface method:

  1. The only effect that needs continual blitting is transparent creatures on
    the map. If this is used sparingly you won’t get speed issues.

  2. You need a S.S. for each creature on the map/level. However with ram in
    machines getting so large this is only an issue if you are making an Age of
    Empires type game with hundreds of units. One thing to note is only a small
    percentage of creatures are visible in these games. So you can share a
    limited set of special surfaces among the visible creatures._________________________________________________________________
    Chat with friends online, try MSN Messenger: http://messenger.msn.com

I’ve seen many people ask about using OpenGL with 2D games and I felt
compelled to say something. Hopefully this will help some of those
people.

One thing I discovered when using OpenGL in 2D games is it isn’t
necessary and it severely limits what you can do in your 2D game. Once
you load all of those images onto the graphics card you cannot read and
write pixels. If you don’t have that capability you can’t have pulsing
creatures and weapons (like Baldurs Gate).

Just the other day, I was playing around with some massive particle
effects (thousands of interpolated pixels), as well as iterative fading
and blurring in OpenGL. (Will release the code as soon as I’ve made it
totally frame rate independent. The iterative texture filters complicates
that a little.) I don’t see where the problem is…

As to the “pulsing creatures” and stuff, IMHO, doing it with true
additive blending with one or more still or animated "effect textures"
looks much better than most of the old palette and pixel tricks.

Recently I invented a method of drawing which lets you make use of
almost any effect in software mode without affecting your frame rate. I
call it the Special Surface Method. I’m sure the big companies used it
in the days of yore.

[…Special Surface Method:…]

So what’s preventing you from applying that to OpenGL, as a form of
procedural textures? (That’s how I made those particle effects.)

Pumping graphics to the video card isn’t that much (if at all) slower
than plain 2D blitting to VRAM, so you lose little in s/w rendering
speed, while you gain incredible amounts of real time blending power.

Drawbacks of the Special Surface method:

  1. The only effect that needs continual blitting is transparent
    creatures on the map. If this is used sparingly you won’t get speed
    issues.

That’s a non-issue with OpenGL. For practical situations, it costs
virtually nothing on most 3D cards. (Even the old G400 can do several
layers of blending, full screen, 640x480 and still keep up a decent frame
rate!)

  1. You need a S.S. for each creature on the map/level.

Likewise with OpenGL.

However with ram
in machines getting so large this is only an issue if you are making an
Age of Empires type game with hundreds of units. One thing to note is
only a small percentage of creatures are visible in these games. So you
can share a limited set of special surfaces among the visible
creatures.

I think this applies to most games. And if you really end up having
hundreds of “enemies” on screen, who’s going to notice if you cheat some
with the advanced effects?

Of course, if you can get away with OpenGL blending and “effect sprites”,
there’s not an issue in the first place. And even if you need s/w
effects, keep in mind that there is only so much screen space: Several
hundreds of objects on screen will most likely mean that they’re very
small, and the real issue with both s/w rendering and OpenGL + procedural
texturs is pixels/frame, not object count.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Saturday 02 February 2002 03:21, David Moffatt wrote: