31.2 Using a background bitmap


Suppose we want to use a background bitmap as a resource. The basic idea is that when we draw the view we want to do the following.

  • Copy the background bitmap to a memory window.

  • Write the critter sprites on top of the memory window as well.

  • Copy the memory window to the screen.

What we need to do is to store our background bitmap in a ready-to-use form. At the high level, we wrap it up inside a cSpriteIcon object. In Windows graphics, we implement the image as a cMemoryDC , and in OpenGL we save it as a cTexture both of which are classes invented for use in the Pop Framework.

A complication comes up. We want our program to be size-independent; that is, if we resize the window, we want the whole background bitmap to show. In Windows graphics, we could use a StretchBlt operation to keep stretching the background bitmap to fit the view's current size. But StretchBlt is a rather slow operation compared to BitBlt . So what we do is to equip the cGraphicsMFC object used for Windows graphics and the cGraphicsOpenGL object used for OpenGL graphics with methods for adjusting the size of a cSpriteIcon to fit the current window size. The author hardly even likes to think about the numb weeks of insane coding frenzy that it took to implement this. For the gory details, see the graphicsMFC .* and graphicsopengl .* files.



Software Engineering and Computer Games
Software Engineering and Computer Games
ISBN: B00406LVDU
EAN: N/A
Year: 2002
Pages: 272

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net