Archived

This topic is now archived and is closed to further replies.

Moe

clearing the backbuffer (easy question)

Recommended Posts

I am slowling learning to make a tile engine. So far, I have a Direct Draw exclusive mode demo using page flipping. How do I go about clearing the back buffer when I need to draw the next frame? Shrapnel Games

Share this post


Link to post
Share on other sites
If you are using a tile engine then there is no need to clear the back buffer really. If you have tiles on every part of the screen, then just redrawing all your tiles will be fine. Clearing the backbuffer may not take up too many CPU cycles but they are CPU cycles that could be used in other parts of the game or just speed your program up a little more.
Lets take a mario game for example. They draw the tile map, then draw all the animated characters. Instead of clearing the back buffer the first thing you can do is draw the tile map, which will draw over everything (inclding the animated characters, in essence erasing them), and then draw your animated characters.


"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

Share this post


Link to post
Share on other sites
I am not that far into making a tile engine (to just redraw the tiles that aren''t changed). I have also run into another problem. I can''t seem to get colorkeying to work. Here is the code I am using to get the mouse position and blit a bitmap at it''s location (with the cursor off, so it looks like a custom color cursor):

case WM_MOUSEMOVE:
{
DDCOLORKEY key;

key.dwColorSpaceLowValue = 0;
key.dwColorSpaceHighValue = 0;
lpddsback->SetColorKey(DDCKEY_SRCBLT,&key);

lpddsback->Blt(NULL,lpbackground,NULL,DDBLT_WAIT,NULL);

//do that neat cursor thingy here
//extract mouse position
int mouse_x = (int)LOWORD(lparam);
int mouse_y = (int)HIWORD(lparam);
int buttons = (int)wparam;

RECT dest;
dest.left = mouse_x;
dest.top = mouse_y;
dest.right = mouse_x+32;
dest.bottom = mouse_y+32;


lpddsback->Blt(&dest,lpcursor,NULL,DDBLT_WAIT | DDCKEY_SRCBLT,NULL);


} break;

As you could have guessed, the cursor bitmap is loaded into the surface lpcursor. I have a background bitmap that is loaded into the surface lpbackground. In my main game loop, all I do is flip the primary and secondary surfaces. I can''t get this to work for the life of me. Anyone see anything wrong? I sure can''t.

Shrapnel Games

Share this post


Link to post
Share on other sites
Here''s what I see:
1) A source color key is a pixel color that is not copied from the source surface during a Blt. This means that it is associated with the *source* surface. This means that you should probably be calling lpcursor->SetColorKey.
2) The flag to tell Blt() to pay attention to the source color key is DDBLT_KEYSRC, not DDCKEY_SRCBLT.

Hope this helps.
...Syzygy

Share this post


Link to post
Share on other sites