Re: Direct Draw Blitting bitmaps to primary surface

Started by
6 comments, last by GameDev135 22 years, 8 months ago
I have 3 surfaces: The primary surface is a spaceship. The back buffer to it is the same spaceship with some lights on. I keep having them flip so it gives the effect of blinking lights. I have added a bitmap (just random lines since this was just to test). The bitmap is moving 5 pixels to the right and 5 pixels down every frame. However, the bitmap doesn't "erase" from the place it moves from. How can I get it to "erase" What I did is blit the bitmap onto the backbuffer and then I flip the pages. I can certainly see why this would create a problem, but I dont know how to correct it. Thanks Daniel Edited by - GameDev135 on August 11, 2001 8:38:43 PM
Feel free to email me at NYYanks432@hotmail.com if you have any questions
Advertisement
Hi,
This is a terribly inefficient way of doing things... so I''m goign to try to steer you in the right direction ( or at least what I think is the right direction... others may disagree ).

Instead of keeping one image on the primary surface and one image on the backbuffer, only draw to the backbuffer.

Keep some kind of variable to tell you which animation the large screen is on ( ie: your big ship that keeps blinking ). Draw the big ship to the backbuffer, then draw the test bitmap to the backbuffer, flip, update variable, repeat.

here''s some psuedo code:

//Make 2 surfaces to hold your large ship - one surface with
//Lights off, the other with lights on
DDrawSurface animShipFrame[2];
animShipFrame[0] = noBlinkingLightsImage;
animShipFrame[1] = BlinkingLightsImage;

int animShip = 0;
//Blt to the backbuffer depending on which frame you on
BltToBackBuffer( animShipFrame[ 0 ] );
//Do whatever to move your test image
MoveTestBMP();
//Blt the test image
BltToBackBuffer( testBMP );
//Flip the surfaces
Flip();

//Change the frame the large ship is on
if ( animShip == 0 ) animShip = 1 else animShip = 0;

I hope that helped... I''m sure it wasn''t the easiest thing in the world to follow, and I make no claims that it is the best way of doing things. But as a general rule, don''t draw directly to the primary buffer - that''s the whole reason you have the backbuffer.

--Nairb

You need to do something like this:

  void renderloop(void){    n = 1-n;    // clear back buffer    // blit space_ship[n] to backbuffer    // blit random_line_bitmap to backbuffer    // flip }  


So you will need the following surfaces:

1. space ship with lights off (space_ship[0])
2. space ship with lights on (space_ship[1])
3. random line bitmap
4. primary surface
5. backbuffer surface

Generally you never draw to the primary surface, only the backbuffer. Then you flip once, after you''ve drawn everything to the back buffer.


I have created the surfaces, but now the blinking isnt working. What it does is it starts off, then goes to on and then stops animating. I think something is wrong with my if clause. And the random lines are now acting very strange. At some parts of the screen, they have dissapeared, but at others they haven't.

Here is the code I have used to test:

//defined globally
bool blink = 0;

//inside the game_main function
RECT dest_rect, source_rect;
dest_rect.left =0;
dest_rect.top = 0;
dest_rect.right = 639;
dest_rect.bottom = 479;
source_rect.left = 0;
source_rect.top = 0;
source_rect.right = 639;
source_rect.bottom = 479;
if (blink ==1) {

if (FAILED(lpddsback->Blt(&dest_rect,spaceblink,&source_rect,(DDBLT_WAIT | DDBLT_KEYSRC), NULL)))
return 0;

}
if (blink == 0) {

if (FAILED(lpddsback->Blt(&dest_rect,spacenoblink,&source_rect,(DDBLT_WAIT|DDBLT_KEYSRC),NULL)))
return 0;

}
if (blink == 0) blink =1;
if (blink == 1) blink = 0;
dest_rect.left = x;
dest_rect.top = x;
dest_rect.right = x + 63; // 63 because the image is 64 *64 pixels
dest_rect.bottom = x + 63;
x += 5;
source_rect.left = 0;
source_rect.top = 0;
source_rect.right = 63;
source_rect.bottom = 63;



if (FAILED(lpddsback->Blt(&dest_rect, lines,&source_rect,
(DDBLT_WAIT | DDBLT_KEYSRC), NULL)))
return 0;



while(FAILED(lpddsprimary->Flip(NULL,DDFLIP_WAIT)));



Sorry if this is hard to read. (How do you make the background white the way "anonymous poster" did?)

Edited by - GameDev135 on August 11, 2001 9:46:06 PM

Edited by - GameDev135 on August 11, 2001 10:09:21 PM
Feel free to email me at NYYanks432@hotmail.com if you have any questions
Hi,
Here''s one problem:

if ( blink == 0 ) blink = 1;
if ( blink == 1 ) blink = 0;

Give yourself a minute to figure out what''s wrong with that before I tell you ;-)

...
...
...

Ok, give yourself enough time?
The way that''s set up, blink will always be 0!! If it''s 0 you set it to 1, then if it''s 1, you set it to 0, so it doesn''t change. Use an else-if. It should be something like:

if ( blink == 0 ) blink = 1;
else blink = 0;

I''m not sure why your test bmp is acting strangely. Maybe the other guy will see the problem, because I didn''t.

--Nairb
Thank you Nairb, now the blinking is fine. I changed it to
"blink = !blink; "

The random lines seem to appear, then go behind the spaceship, and then reappear after the spaceship ends. Basically the random lines move fine, just there are remnants of them in certain places.

Could it somehow be the way the bitmap is saved or could it be the color key ?

Edited by - GameDev135 on August 11, 2001 10:18:42 PM
Feel free to email me at NYYanks432@hotmail.com if you have any questions
Hi,
I think it''s the fact that your big bitmap is using a color key. Since nothing is being drawn below your large ship, don''t use the color key. If you still want/need the color key, you''re going to need to clear the screen before you blit the ship.

--Nairb
Thanks a lot. It works now!

I was using the color key to make black transparent so when the lines were over the black area, nothing showed up.
Feel free to email me at NYYanks432@hotmail.com if you have any questions

This topic is closed to new replies.

Advertisement