• ### Popular Now

• 12
• 12
• 9
• 10
• 13

#### Archived

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

# Re: Direct Draw Blitting bitmaps to primary surface

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

## Recommended Posts

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

##### Share on other sites
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];

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

##### Share on other sites

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.

##### Share on other sites
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

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

return 0;

}

return 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

##### Share on other sites
Hi,
Here''s one problem:

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:

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

--Nairb

##### Share on other sites
Thank you Nairb, now the blinking is fine. I changed it to

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

##### Share on other sites
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