Surface doesn't draw after Restoring it

Started by
2 comments, last by BornToCode 18 years, 3 months ago
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,NULL);
		DDSetColorKey(frames,rgb);
	}
}

Any clue? Thanks in advance.
Advertisement
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...
Stay Casual,KenDrunken Hyena
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.
If you're interested, read more of what I have to say at my DirectX9 site. - Segment Fault
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.

This topic is closed to new replies.

Advertisement