Jump to content
  • Advertisement

Archived

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

flukus

Need help with loading palettes

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

Basicly I have this code, most of which is from TOWGPG (Sick of andre lamothe yet?): for (int colour=1; colour < 255 ; colour++) { palette[colour].peRed = rand()%256; palette[colour].peGreen = rand()%256; palette[colour].peBlue = rand()%256; //set flag palette[colour].peFlags = PC_NOCOLLAPSE; }//end for //set first palette colour to blck palette[0].peRed = 0; palette[0].peGreen = 0; palette[0].peBlue = 0; palette[0].peFlags = PC_NOCOLLAPSE; palette[255].peRed = 255; palette[255].peGreen = 255; palette[255].peBlue = 255; palette[255].peFlags = PC_NOCOLLAPSE; if (FAILED(lpdd->CreatePalette(DDPCAPS_8BIT | DDPCAPS_INITIALIZE | DDPCAPS_ALLOW256, palette, &lpddpal, NULL))) MessageBox(main_window_handle, "error", "error", NULL); The problem is that the palette never gets created and I don''t have the slightest idea why!

Share this post


Link to post
Share on other sites
Advertisement
You''re forgetting one statement. This is how you should load the palette correctly:


  
if (FAILED(lpdd4->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 | DDPCAPS_INITIALIZE, Palette, lpddPal, NULL)))
return (FAILED_PAL_CREATE);

if (FAILED(lpddsPrimary->SetPalette(lpddPal)))
return (FAILED_PAL_ATTACH);


You forgot the SetPalette routine. Gope it helps!

Sand Hawk

----------------
-Earth is 98% full. Please delete anybody you can.


My Site

Share this post


Link to post
Share on other sites
I''ve got SetPalette further down the program but it crashes at that point because the palette was never created.

Share this post


Link to post
Share on other sites
Check all your return codes properly, don''t just use FAILED.


HRESULT hr;

hr = (your directdraw call)
if (FAILED (hr))
{
// now report the error code so you can use the directx error lookup utility to find the cause.
}



Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

Share this post


Link to post
Share on other sites
Looking at you code, why aren''t you using lpdd4->CreateSurface?? I thought you needed to use the lpdd4 to create the palette and not the lpdd(DirectX 1 interface). I wrote already an DirectDraw wrapper class and this is my init function and my loadpalette/savepalette functions:


  
//////////////////////////////////////////////////////////////////////////////////////////

// I N I T

//

// Initialize DirectDraw6, including the creation of 2 surfaces

//////////////////////////////////////////////////////////////////////////////////////////

int DirectDraw::Init(HWND hWndApp, int ScreenWidth, int ScreenHeigth, int UsedBpp)
{
hWnd = hWndApp;
Width = ScreenWidth;
Heigth = ScreenHeigth;
Bpp = UsedBpp;

// CDebug Log("C:\\DDrawInit.log");

DDSURFACEDESC2 ddsd; // DDraw 6 surface description

LPDIRECTDRAW lpdd = NULL; // Temp DirectDraw1 interface, needed to get DDraw6 interface


hWnd = hWndApp;

// Request a DirectDraw1 interface. When failed the function returns a 1 to tell it failed

// on creating the DDraw1 surface.

if (FAILED(DirectDrawCreate(NULL, &lpdd, NULL)))
return (FAILED_INIT_DX1);

// Query an interface for DirectDraw6. IID_IDirectDraw4 is DDraw6, M$ fucked up with the

// numbers

if (FAILED(lpdd->QueryInterface(IID_IDirectDraw4, (LPVOID *)&lpdd4)))
return (FAILED_INIT_DX6);

// Release the DirectDraw1 interface, it''s no longer needed.

lpdd->Release();
lpdd = NULL;

// Set cooperation level with Windows. Needed because DX is gonna take over alot of

// things from Windows and is going to be full screen.

if (FAILED(lpdd4->SetCooperativeLevel(hWnd,
DDSCL_FULLSCREEN |
DDSCL_ALLOWMODEX |
DDSCL_EXCLUSIVE |
DDSCL_ALLOWREBOOT)))
return (FAILED_INIT_COOP);

// Set the displaymode

if (FAILED(lpdd4->SetDisplayMode(ScreenWidth, ScreenHeigth, UsedBpp, 0, 0)))
return (FAILED_INIT_SETDISPLAY);

// Fill up some stuff needed to create a surface

DDRAW_INIT_STRUCT(ddsd); // Replaces above 2 lines.

ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
ddsd.dwBackBufferCount = 1;

// Create primary surface, using the ddsd struct from above

if (FAILED(lpdd4->CreateSurface(&ddsd, &lpddsPrimary, NULL)))
return (FAILED_INIT_PRIMARY_BUFFER);

// Create the back(secondary) buffer.

ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;

if (FAILED(lpddsPrimary->GetAttachedSurface(&ddsd.ddsCaps, &lpddsBack)))
return (FAILED_INIT_SECONDARY_BUFFER);

// return success

return (SUCCESS);
}

//////////////////////////////////////////////////////////////////////////////////////////

// L O A D P A L E T T E

//

// Load the palette and attach it to the surfaces.

//////////////////////////////////////////////////////////////////////////////////////////

int DirectDraw::LoadPalette(char File[1024])
{
ifstream Input(File, ios::binary);

// If the file didn''t succeed to open

if (!Input)
{
MessageBox(NULL, "Failed to open", "Failed", MB_OK);
return (8);
}

// Check for failure to read the data from file

if (!(Input.read((char *) &Palette, sizeof(Palette))))
{
MessageBox(NULL, "Failed to open", "Failed", MB_OK);
return (9);
}

// Close the file

Input.close();

// Attach the palette for the primary surface, but first check if there isn''t already one

// attached

if (lpddPal == NULL)
{
// No palette attached, so attach it now

if (FAILED(lpdd4->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 | DDPCAPS_INITIALIZE,
Palette, &lpddPal, NULL)))
return (FAILED_PAL_CREATE);

// Attach the palette to the surface

if (FAILED(lpddsPrimary->SetPalette(lpddPal)))
return (FAILED_PAL_ATTACH);
}
else
{
// There is already an palette attached, so we have to update it

if (FAILED(lpddPal->SetEntries(0, 0, MAX_PAL_COLORS, Palette)))
return (FAILED_PAL_UPDATE);
}

return (SUCCESS);
}

//////////////////////////////////////////////////////////////////////////////////////////

// U P D A T E P A L E T T E

//

// Update the current palette with a new one and automaticly update the palette stored

// inside the struct

//////////////////////////////////////////////////////////////////////////////////////////

int DirectDraw::UpdatePalette(PALETTEENTRY NewPalette[MAX_PAL_COLORS])
{
// Update the palette inside the DDrawStruct, then update the palettes used by DirectDraw

for (int Index = 0; Index < 256; Index++)
Palette[Index] = NewPalette[Index];

// Attach the palette for the primary surface, but first check if there isn''t already one

// attached

if (lpddPal == NULL)
{
// No palette attached, so attach it now

if (FAILED(lpdd4->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 | DDPCAPS_INITIALIZE,
Palette, &lpddPal, NULL)))
return (FAILED_PAL_CREATE);

// Attach the palette to the surface

if (FAILED(lpddsPrimary->SetPalette(lpddPal)))
return (FAILED_PAL_ATTACH);
}
else
{
// There is already an palette attached, so we have to update it

if (FAILED(lpddPal->SetEntries(0, 0, MAX_PAL_COLORS, Palette)))
return (FAILED_PAL_UPDATE);
}

return (SUCCESS);
}

Hope this helps. You need to change the code a little(Remove the msgboxes. These are still debug versions).

Sand HAwk


----------------
-Earth is 98% full. Please delete anybody you can.


My Site

Share this post


Link to post
Share on other sites
"Looking at you code, why aren''t you using lpdd4->CreateSurface?? I thought you needed to use the lpdd4 to create the palette and not the lpdd(DirectX 1 interface). I wrote already an DirectDraw wrapper class and this is my init function and my loadpalette/savepalette functions:"

lpdd is the directdraw7 interface.

"Check all your return codes properly, don''t just use FAILED."

Where can I find all the possible return codes?

Share this post


Link to post
Share on other sites
You just have your program print out return codes so you can use the DirectX Error Lookup utility which is in the SDK.

All DirectX functions return an HRESULT - which is the return code. Also the docs tell you which return codes to expect from which functions.

It''s all in the SDK... all in the SDK...


Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!