Jump to content
  • Advertisement
Sign in to follow this  

DDraw CreateSurface fails with DDERR_INVALIDPIXELFORMAT

This topic is 2921 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


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

// this dwFlags works!
ddsdBackBuffer.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;

ddsdBackBuffer.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY;
ddsdBackBuffer.dwWidth = (DWORD) rcRect.right; // is 512
ddsdBackBuffer.dwHeight = (DWORD) rcRect.bottom; // is 512

ddsdBackBuffer.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!

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!