Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


IDirectDrawSurface::Blt function return DDERR_SURFCAELOST


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 zhangfree   Members   -  Reputation: 103

Like
0Likes
Like

Posted 22 November 2012 - 07:17 PM

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.

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS