Sign in to follow this  

Surface doesn't draw after Restoring it

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, everyone! I have a little problem with DirectX: After creating a Surface that is stored on video memory ( DDSCAPS_VIDEOMEMORY ), the surface draws well on full-screen. But when I minimize the application and come back to it, I see nothing ( I did include restoring the Surface if it is lost ). I tried storing the Surface on system memory ( DDSCAPS_SYSTEMMEMORY ). That way it fully works, but I think that it would be better to store them in video memory when possible. Here is my code:
//-----------------------------------------------------------------------------
// Func: cSprite(int FrameNumber, int width, int height, LPCSTR szBitmap, 
//					 LPDIRECTDRAW lpdd, COLORREF rgb, int SkipFrame)
// Desc: Create the bitmaps and surfaces from a bitmap file.
//-----------------------------------------------------------------------------
cSprite::cSprite(int FrameNumber, int width, int height, LPCSTR szBitmap, 
					 LPDIRECTDRAW lpdd, COLORREF rgb, int SkipFrame)
{
	NumFrames=FrameNumber;
	FrameSkip=SkipFrame; // play speed ( 1 = fastest, 10 = very slow )
	NumFrames*=FrameSkip;
	CurrFrame=0;
	rect.bottom=height;	rect.right=width;
	rect.left=0;		rect.top=0;
	bitmap.Bitmap_Load(lpdd, szBitmap, rgb);
	frames=new LPDIRECTDRAWSURFACE[NumFrames];

	DDSURFACEDESC ddsd;
	ddsd.dwSize=sizeof(ddsd);
	ddsd.dwFlags=DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH;
	ddsd.ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;
	ddsd.dwHeight=height;
	ddsd.dwWidth=width;

	for(int i=0; i< NumFrames; i++)
	{
		lpdd->CreateSurface(&ddsd,&frames[i],NULL);
		DDSetColorKey(frames[i],rgb);
	}
}

Any clue? Thanks in advance.

Share this post


Link to post
Share on other sites
I haven't touched DirectDraw in a very long time, so this may be completely wrong. I seem to recall that restoring a video memory surface simply enables the surface for reuse, it does not restore the contents of the surface, so you would need to reload the data.

Or I could be completely wrong. It's been years...

Share this post


Link to post
Share on other sites
That's right -- you're responsible for recreating the contents of the surface in this case. If you were dealing with vertex buffers, you'd be reponsible for recreating the vertex data.

Share this post


Link to post
Share on other sites
Drunken Hyena is correct all it does is restore the surface, you will need to reload the image back into the surface. So here is a rule of thumb, for big images store them in system memory so you do not have to load them again, just in case you get a lost device, and for small images have them in video memory since they can be loaded very fast, if you get a lost device.

Share this post


Link to post
Share on other sites
Sign in to follow this