Jump to content
  • Advertisement


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


clearing the backbuffer (easy question)

This topic is 6548 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
You have to do a blt on the backbuffer using a colorfill. Look in the sdk about the blt flags to see how to use the colorfill.

*** Triality ***

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):


key.dwColorSpaceLowValue = 0;
key.dwColorSpaceHighValue = 0;


//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.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!