Jump to content
  • Advertisement

Archived

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

Shadwdrak

Direct Draw problems in 8bpp

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

I am still having this strange problem with the palette in my program. I load the palette from a bitmap using the DDLoadPalette function, I know at least some colors are making it into the palette because if I omit the LoadPalette function the image appears in a strange variety of yellows and blues. Here is all the DirectX setup code in my program. Sorry for the length, but since I am not sure where the problem lies I wanted to include it all. /////////////////////////////////////// //// DXSETUP ////////////////////////// /////////////////////////////////////// bool DXSetup(LPCTSTR &error) { HRESULT ddrval; ddrval = DirectDrawCreateEx(NULL, (VOID**)&lpDD, IID_IDirectDraw7, NULL); if (ddrval != DD_OK) { // Direct Draw object has not been created error = "FAILED: DirectDrawCreateEx"; return false; } // Get control of the display with SetCooperativeLevel() ddrval = lpDD->SetCooperativeLevel(hwnd,DDSCL_EXCLUSIVE / DDSCL_FULLSCREEN); if(ddrval != DD_OK) { // SetCooperativeLevel failed error = "FAILED: SetCooperativeLevel"; return false; } // Set display mode ddrval = lpDD->SetDisplayMode(MODEWIDTH, MODEHEIGHT, BPP,0,0); if(ddrval != DD_OK) { // couldent set display mode error = "FAILED: SetDisplayMode"; return false; } // Ceate main drawing surface and back buffer with CreateSurface(); ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS / DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE / DDSCAPS_FLIP / DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; ddrval = lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL); if(ddrval != DD_OK) { // couldent create surface error = "FAILED: CreateSurface (primary)"; return false; } // Get a pointer to the backbuffer ddscaps.dwCaps = DDSCAPS_BACKBUFFER; ddrval = lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpDDSBack); if(ddrval != DD_OK) { // couldent get backbuffer error = "FAILED: GetAttachedSurface (backbuffer)"; return false; } // Create and set the palette lpDDPal = DDLoadPalette(lpDD, MAKEINTRESOURCE(IDB_GRS01)); if(lpDDPal == NULL) { error = "DDLoadPalette FAILED"; return false; } if(lpDDSPrimary->SetPalette(lpDDPal) != DD_OK) { error = "SetPalette FAILED"; return false; } return true; // Return true if no errors }; Below is part of the header file // DirectDraw GLOBALS LPDIRECTDRAW7 lpDD; LPDIRECTDRAWSURFACE7 lpDDSPrimary; LPDIRECTDRAWSURFACE7 lpDDSBack; LPDIRECTDRAWSURFACE7 lpTiles; LPDIRECTDRAWPALETTE lpDDPal = NULL; DDSCAPS2 ddscaps; DDSURFACEDESC2 ddsd; // Windows GLOBALS HWND hwnd; // Handle to the window // Game GLOBALS #define MODEWIDTH 800 #define MODEHEIGHT 600 #define BPP 8

Share this post


Link to post
Share on other sites
Advertisement
oops, I didnt really specify what my question is.

Am I doing something that is obviously wrong to make the palette not work correctly?

Shadwdrak - Who feels behind 90% of the people on the board.

Share this post


Link to post
Share on other sites
I had the same problem when I was learning about palettes. After quite a bit of frustration, I found out it wasn't my code. A few things in DDLoadPalette weren't working like I thought they did.

First, make sure you have the name of your bitmap resource correct when calling DDLoadPalette. If it can't find your bitmap, it returns a default palette (I edited my copy of ddutil.cpp so it returns NULL instead).

Second, by default DDLoadPalette doesn't build a full 256 color palette, it retains a certain number of entries for the default Windows GDI palette (16, if I remember correctly). You can fix this be editing DDLoadPalette in ddutil.cpp.

I don't have access to my compiler right now, so you'll have to bear with me, but there should be a portion of code in DDLoadPalette that goes something like:


lpDD->CreatePalette (DDPCAPS_8BIT, ape, lpDDPal, NULL);


Change it to:


lpDD->CreatePalette (DDPCAPS_8BIT / DDPCAPS_ALLOW256, ape, lpDDPal, NULL);


Now it should load your full palette.

Hope that helps.

BTW, that should be a pipe symbol (bilogical or) between DDPCAPS_8BIT and DDPCAPS_ALLOW256), not a forward slash.

Edited by - Zer0x1CE on 5/2/00 5:47:38 PM

Share this post


Link to post
Share on other sites
Well thanks for the input but it didnt work. The DDPCAPS_ALLOW256 parameter only allows you to put palette entries in element 0 and 255 of the palette. This normally is reserved for black and white respectivly. It almost seems that it is only loading the more important colors, that is the colors that are being used most often.

again thanks,
Shadwdrak - Who feels that tackling the 555/565 problem may be easier than this palette thing.

Share this post


Link to post
Share on other sites
I''m not sure what''s going wrong. The code you posted looks fine. It could be with the order you''re initializing things, something else in your code, or a problem with you display driver (doubt that last one though).

If you want, we could swap code. I have a fairly straight forward palette loading example I could e-mail you from work tomorrow.

Good luck.

- Zero

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!