DDraw CreateSurface fails with DDERR_INVALIDPIXELFORMAT

Started by
-1 comments, last by Elchtest2009 13 years, 6 months ago
Hi,

Even though DirectDraw has aged a bit by now, but I still would like to use it for the project I am working on.

I am getting an error on CreateSurface if I enable the PIXELFORMAT flag. Otherwise it works fine.

 DDSURFACEDESC2 ddsdBackBuffer;ZeroMemory(&ddsdBackBuffer, sizeof(DDSURFACEDESC2));ddsdBackBuffer.dwSize = sizeof( ddsdBackBuffer );// if DDSD_PIXELFORMAT is enabled then it will fail below at CreateSurface// ddsdBackBuffer.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;// this dwFlags works!ddsdBackBuffer.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;ddsdBackBuffer.ddsCaps.dwCaps =  DDSCAPS_SYSTEMMEMORY;ddsdBackBuffer.dwWidth  = (DWORD) rcRect.right;  // is 512ddsdBackBuffer.dwHeight = (DWORD) rcRect.bottom; // is 512ddsdBackBuffer.ddpfPixelFormat.dwSize = sizeof(ddsdBackBuffer.ddpfPixelFormat);ddsdBackBuffer.ddpfPixelFormat.dwFlags = DDPF_ALPHAPIXELS | DDPF_RGB; ddsdBackBuffer.ddpfPixelFormat.dwRGBBitCount = 24;ddsdBackBuffer.ddpfPixelFormat.dwAlphaBitDepth = 8;ddsdBackBuffer.ddpfPixelFormat.dwRBitMask = 0xFF000000;ddsdBackBuffer.ddpfPixelFormat.dwGBitMask = 0x00FF0000;ddsdBackBuffer.ddpfPixelFormat.dwBBitMask = 0x0000FF00;ddsdBackBuffer.ddpfPixelFormat.dwRGBAlphaBitMask = 0x000000FF;	HRESULT ddrval2 = lpDD->CreateSurface(&ddsdBackBuffer, &lpDDSBack, NULL );if( ddrval2 != DD_OK ) {  if(ddrval2 == -2005532527){	cout << "lpDD->CreateSurface Failed: DDERR_INVALIDPIXELFORMAT" << endl;  }}


I also uploaded a sample program that compiles with VS2008 if you have the June 2010 DX SDK or later installed. It draws random colors in the first half of the window. You can easily toggle between the version that does not use the pixelformat flag and returns S_OK at CreateSurface() and the non working version that returns DDERR_INVALIDPIXELFORMAT. Sample: www.idfun.de/temp/ddrawtest.rar

Thanks for looking at it!

This topic is closed to new replies.

Advertisement