#### Archived

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

# clearing a directdrawsurface

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

## Recommended Posts

I''m pretty tired and I''m *really* frustrated (both with my program, and my dog...dog just chewed one of my cables in half) so I''m probably not going to give important info here...so please let me know if there''s info that''s needed to help me figure this out. I have a mini-third buffer (this is tetris and I don''t update the scoreboard yet, so this is a surface that only blits over the playfield). The pieces fall into place and you can see that clear enough...I blit the play field to the backbuffer (over the background image) and flip-page it to the primary surface once per cycle. So you can see my stacked pieces without fail, but the image itself is otherwise filled with garbage: I floodfill it with my transparency color, which shouldn''t copy in a blit, but still...instead of seeing my own background image, it gets covered in crap. So basically I see a column of motionless static (one time I saw the aol insignia distored all over it; this lead me to believe it was a pointer error but everything in that way seemed to be in order). If I floodfill it with a different color, black, a random color, don''t floodfill it at all, it''s as if I don''t floodfill it at all anyway. How can I be *sure* that the surface is cleared out to black before getting started? (I''d rather see a black rectangle over my background than this white/black/staticky crap). Here''s my current floodfill routine:
void CApplication::DDFillSurfaceWithColor(LPDIRECTDRAWSURFACE7 lpdds, DWORD color) // a clearscreen function =)

{
DDBLTFX ddbltfx; // this contains the DDBLTFX structure

// clear out the structure and set the size field

DD_INIT_STRUCT(ddbltfx);

// set the dwfillcolor field to the desired color

ddbltfx.dwFillColor = color;

// ready to blt to surface

lpdds->Blt(NULL,       // ptr to dest rectangle

NULL,       // ptr to source surface, NA

NULL,       // ptr to source rectangle, NA

DDBLT_COLORFILL | DDBLT_WAIT,
&ddbltfx);  // ptr to DDBLTFX structure

}

Like I said, I''ve tried to fill it, both once and once-per-cycle, with every color under the sun, and well...you wouldn''t know it. Funny enough the tetris-pieces all piled up are crisp and clear over this otherwise-garbagefilled surface. I blit those to it after flood-filling it (which I''d figure would clear it), and well...I hate this. I''m working in 32-bit color mode, 800x600. I switched it to 16-bit color mode to see if that changed anything, and all it changed was the color-gradient of the garbage, and the picture quality of my background. Any additional info you might need I''ll provide. I''ve been rackin my brain on this for days now.

##### Share on other sites
I didn''t think I was *that* tired.

I''ll try to simplify it.

Where lpdd is my Direct Draw Object pointer: I''ve created a Direct Draw Surface, say...

LPDIRECTDRAWSURFACE7 lpdds;DDSURFACEDESC2 ddsd;memset(&ddsd, 0, sizeof(ddsd));ddsd.dwSize = sizeof(ddsd);ddsd.dwFlags = DDS_OFFSCREENPLAIN;ddsd.dwWidth = BITMAP_WIDTH; // previously definedddsd.dwHeight = BITMAP_HEIGHT; // prev definedlpdd->CreateSurface(&ddsd, &lpdds, NULL);

Now, lpdds is an offscreen surface in video memory. (There''s enough vid mem because, well, it''s the only surface in mem other than the primary surface and it''s attached backbuffer.) My question is how do I set the entire thing to a big, black bitmap? I''m using IDirectDrawSurface7::Blt - using DDBLT_COLORFILL (setting dwFillColor in the DDBLTFX STRUCT to zero) and it doesn''t seem to be working.

The more I look thru my program the more I realize that anywhere I''ve used this method (using IDirectDrawSurface7::Blt to floodfill a surface with a color), I''ve soon after blitted a bitmap (loaded from the disk) on to the surface I floodfilled. So this is, in effect, the first time I am seeing a surface that I''ve filled with Blt displayed onscreen.

So my questions are:

1. Are there known problems with using Blt to floodfill? How is it used properly? (You can see my code for that above in my initial post.)

2. Is there an alternative to floodfilling with Blt? Can I "Lock" the surface and just brute-force set all of its pixels to black (or whatever color I want to floodfill with)?

3. Now that I think of it, will memset work?

4. Anything else you think might help. =)

##### Share on other sites
Not that anyone''s paying this post any mind because, as I said, I was tired when I posted it and it made rather little sense...though admittedly I felt my second post here put my problem concisely...

Anyway, I figured it out, and it''s a lesson we should all remember.

I forgot to set ddbltfx.dwSize = sizeof(ddbltfx).

And the WEIRDEST shit was happening.

Anyway, seems to work now. Don''t forget the dwSize field ever =)

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
16
5. 5

• 9
• 12
• 9
• 33
• 13
• ### Forum Statistics

• Total Topics
632593
• Total Posts
3007276

×