Sign in to follow this  
zhangfree

IDirectDrawSurface::Blt function return DDERR_SURFCAELOST

Recommended Posts

zhangfree    103
When I run the code DEMO7_8 from the book tricks of the windows game programming gurus , the Blt function reurns DDERR_SURFACELOST , what is wrong with it? thank you for your reply!

The following is the main part of the code:

int Game_Main(void *parms = NULL, int num_parms = 0)
{
// this is the main loop of the game, do all your processing
// here

DDBLTFX ddbltfx; // the blitter fx structure
static int feeling_counter = 0; // tracks how we feel :)
static int happy = 1; // let's start off being happy

// make sure this isn't executed again
if (window_closed)
return(0);

// for now test if user is hitting ESC and send WM_CLOSE
if (KEYDOWN(VK_ESCAPE))
{
PostMessage(main_window_handle,WM_CLOSE,0,0);
window_closed = 1;
} // end if

// use the blitter to erase the back buffer
// first initialize the DDBLTFX structure
DDRAW_INIT_STRUCT(ddbltfx);

// now set the color word info to the color we desire
ddbltfx.dwFillColor = 0;

// make the blitter call

// lock the back buffer surface

if ((lpddsback->Blt(NULL, // pointer to dest RECT, NULL for whole thing
NULL, // pointer to source surface
NULL, // pointer to source RECT
DDBLT_COLORFILL | DDBLT_WAIT,
// do a color fill and wait if you have to
&ddbltfx))) // pointer to DDBLTFX holding info
{
return 0;
}

// initialize ddsd
DDRAW_INIT_STRUCT(ddsd);

if (FAILED(lpddsback->Lock(NULL,&ddsd,
DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,
NULL)))
{
MessageBox(NULL,"Lock Error!", "", NULL);
return(0);
}

// increment how we feel
if (++feeling_counter > 200)
{
feeling_counter = 0;
happy = -happy;
} // end if

// draw all the happy faces
for (int face=0; face < 100; face++)
{
// are we happy or sad?
if (happy==1) // we are happy :)
Blit_Clipped(happy_faces[face].x,
happy_faces[face].y,
8,8,
happy_bitmap,
(UCHAR *)ddsd.lpSurface,
ddsd.lPitch);
else // we must be sad :(
Blit_Clipped(happy_faces[face].x,
happy_faces[face].y,
8,8,
sad_bitmap,
(UCHAR *)ddsd.lpSurface,
ddsd.lPitch);

} // end face

// move all happy faces
for (int face=0; face < 100; face++)
{
// move
happy_faces[face].x+=happy_faces[face].xv;
happy_faces[face].y+=happy_faces[face].yv;

// check for off screen, if so wrap
if (happy_faces[face].x > SCREEN_WIDTH)
happy_faces[face].x = -8;
else
if (happy_faces[face].x < -8)
happy_faces[face].x = SCREEN_WIDTH;

if (happy_faces[face].y > SCREEN_HEIGHT)
happy_faces[face].y = -8;
else
if (happy_faces[face].y < -8)
happy_faces[face].y = SCREEN_HEIGHT;

} // end face

// unlock surface
if (FAILED(lpddsback->Unlock(NULL)))
return(0);

// flip the pages
while (FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT)));

// wait a sec
Sleep(30);

// return success or failure or your own return code here
return(1);

} // end Game_Main.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this