Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Dave2001

SetPalette returns DDERR_INVALIDPIXELFORMAT

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

Hi, I'm having a problem with setting a palette for the primary surface with the function: IDirectDrawSurface7::SetPalette. I'm running using DDSCL_NORMAL in a window. I have a feeling that the problem may be somewhere else in the set up routine, so here's the whole thing.
    

BOOL InitDirectDraw ()
{
#define DDIERR(x) {
MessageBox(hwnd,x,"DirectDraw Error!",MB_OK|MB_ICONEXCLAMATION);return FALSE;}

// Create the main DirectDraw object

if (FAILED (DirectDrawCreateEx (NULL, (void**)&lpdd, IID_IDirectDraw7, NULL)))
  DDIERR ("Unable to create the main DirectDraw object!");

// Set the cooperative level

if (FAILED (lpdd->SetCooperativeLevel (hwnd, DDSCL_NORMAL)))
  DDIERR ("Unable to set the cooperative level to DDSCL_NORMAL!");

// Create the primary surface

DDSURFACEDESC2 ddsd;
ZeroMemory (&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

if (FAILED (lpdd->CreateSurface (&ddsd, &lpddsPrimary, NULL)))
  DDIERR ("Unable to create the primary surface!");

// Create a clipper for the primary surface

if (FAILED (lpdd->CreateClipper (0, &lpddClipper, NULL)))
  DDIERR ("Unable to create the clipper!");
if (FAILED (lpddClipper->SetHWnd (0, hwnd)))
  DDIERR ("Unable to set the clipper to the window!");
if (FAILED (lpddsPrimary->SetClipper (lpddClipper)))
  DDIERR ("Unable to set the primary surface clipper!");

// Initialize a palette

PALETTEENTRY pal[256];
for (int i = 0; i < 256; i++)
{
  pal[i].peRed = (BYTE) (((i >> 5) & 0x07) * 255 / 7);
  pal[i].peGreen = (BYTE) (((i >> 2) & 0x07) * 255 / 7);
  pal[i].peBlue = (BYTE) (((i >> 0) & 0x03) * 255 / 3);
  pal[i].peFlags = (BYTE) 0;
}

// Create and set the palette

if (FAILED (lpdd->CreatePalette (DDPCAPS_8BIT|DDPCAPS_ALLOW256,
  pal, &lpddPal, NULL)))
  DDIERR ("Unable to create the palette!");

// ** This is where it returns DDERR_INVALIDPIXELFORMAT! **

if (FAILED (lpddsPrimary->SetPalette (lpddPal)))
  DDIERR ("Unable to set the palette!");
    
Thanks for your help. Dave2001, MAILTO(Forrester6@msn.com); Edited by - Dave2001 on January 14, 2001 9:53:07 PM

Share this post


Link to post
Share on other sites
Advertisement

  • 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!