Archived

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

windowed game

This topic is 5014 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

Hey!! I''m trying to program my first windowed 2D game using DirectX7 interface. I use two off-screen surfaces to store two diferent bitmaps. The first surface "blits" without any problem, but the second one, which is a sprite, is constantly blinking. Does anybody knows what cause this. Please help me! Thanx in advance!

Share this post


Link to post
Share on other sites
I''m guessing you''re using DirectDraw, and thus, possibly DirectX 7?

From the looks of it, you''re blitting to your backbuffer inconsistently. Look at it this way...

[ ] [ ] <- Two screens.
The first is the primary surface, which is displayed. The second is the backbuffer. We''ll assume your sprite is an ''x''.

[ ] [x] <- Sprite blitted.
[x] [ ] <- Surfaces flipped; the sprite appears.
[ ] [x] <- Surfaces flipped; the sprite doesn''t show anymore

And so forth. Basically, you offly drew the sprite off the backbuffer, and you end up having offe surface with a sprite, and offe without the sprite. You need to update your display constantly if you want to animate the sprite and have the two buffers synchronized. Look at the problem this way...

[ ] <- [ ] <- (code)
You write to the back buffer, which "writes" to the primary surface. Not exactly true: to be technically correct, the primary surface and the backbuffer are swapped. But you get my meaning. After you put stuff off your back buffer and tell DirectDraw to update the display with what''s off the backbuffer, pretend that the stuff off the backbuffer is literally moved to the primary surface and is no longer valid: there''s just junk left there now. No good anymore. This means that every frame you want to clear the backbuffer (because there''s "junk" off it) and redraw your scene. Then DirectDraw has "clean" image data to throw back to the primary surface, and so forth.

In short, you need to constantly update your backbuffer because flip switches the backbuffer and primary surface around, so you could say it swaps the images on them. After calling flip, your backbuffer doesn''t contain valid image data and you have to take care of that otherwise you''ll see one frame that''s ok, and one frame that''s whatever was on the primary surface; next call to flip, things will be back to normal. Next call, things will be swapped around again. Etc.

Share this post


Link to post
Share on other sites