DirectDraw - CreateSurface for offscreen surface fails

Started by
2 comments, last by simon10k 19 years, 1 month ago
Hey, I'm just trying out a DirectDraw tutorial as I need to create a 2d game quickly in order to exemplify some networking code I have. However, I have a problem when I call a function to create an offscreen surface - the call to CreateSurface() always fails. Here's my code:

	LPDIRECTDRAWSURFACE surface = NULL;

	// Clear the ddsd memory
	EraseDesc();

	ZeroMemory( &ddsd, sizeof( ddsd ) );
	ddsd.dwSize = sizeof( ddsd );

	// Fill in the surface info
	ddsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT;
	ddsd.dwWidth = width;
	ddsd.dwHeight = height;
	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN|DDSCAPS_VIDEOMEMORY;

	// Create the surface
	long rval = lpdd->CreateSurface(&ddsd, &surface, NULL);

	if (rval != DD_OK)
	{
		MessageBox(hwnd, "Failed to create offscreen surface", "Error", MB_OK);
		quit = true;
	}
	return surface;
The rval that is returned is: -2147024809 which is not a valid DX error code so that isn't helping. Anyone have an idea what might be causing the function to fail? Cheers!
Advertisement
Quote:Original post by gazsux
Hey,

I'm just trying out a DirectDraw tutorial as I need to create a 2d game quickly in order to exemplify some networking code I have. However, I have a problem when I call a function to create an offscreen surface - the call to CreateSurface() always fails.

Here's my code:
	LPDIRECTDRAWSURFACE surface = NULL;	// Clear the ddsd memory	EraseDesc();	ZeroMemory( &ddsd, sizeof( ddsd ) );	ddsd.dwSize = sizeof( ddsd );	// Fill in the surface info	ddsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT;	ddsd.dwWidth = width;	ddsd.dwHeight = height;	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN|DDSCAPS_VIDEOMEMORY;	// Create the surface	long rval = lpdd->CreateSurface(&ddsd, &surface, NULL);	if (rval != DD_OK)	{		MessageBox(hwnd, "Failed to create offscreen surface", "Error", MB_OK);		quit = true;	}	return surface;


The rval that is returned is: -2147024809 which is not a valid DX error code so that isn't helping.

Anyone have an idea what might be causing the function to fail?

Cheers!


-2147024809 is E_INVALIDARG error code.
I don't know, but don't see any color depth setting.
Color depth is set in another function. Does that have to be set before creating the surface?

[EDIT] - No matter, I have it sorted. Thanks

[Edited by - gazsux on March 16, 2005 7:52:57 PM]
You dont set the color, it is the same as the primary surface.
-----------------------------Language: C++API: Win32, DirectXCompiler: VC++ 2003

This topic is closed to new replies.

Advertisement