I have a couple of quick questions about DirectDraw that I was hoping someone could clear up for me. N00b so these are simple questions that I want cleared up before I continue...
================================================== ======================
The first is about a backbuffer surface and its palette.
- Why do I need to set the palette up for this surface if everything being displayed to the user is on the primary surface? All of the code I have seen sets up the backbuffer surface palette, but I don't understand why. I comment out this code and my program seems to work perfectly fine. My question: So why is it there?
Ex 1-1:
Code:
DDSURFACEDESC ddsd;
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |DDSCAPS_FLIP | DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount = 1;
hRes = gDirectDrawObject->CreateSurface(&ddsd, &gPrimarySurface, NULL);
if(hRes != DD_OK)
return false;
if(!createBlackPalette(&gPrimaryPalette))
return false;
hRes = gPrimarySurface->SetPalette(gPrimaryPalette);
if(hRes != DD_OK)
return false;
DDSCAPS ddscaps;
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
if(FAILED(gPrimarySurface->GetAttachedSurface(&ddscaps, &gSecondarySurface)))
return false;
/* If I comment this section out the program still works fine it appears
if(!createBlackPalette(&gSecondaryPalette)) // Just creates an palette all values = 0.
return false;
if(FAILED(gSecondarySurface->SetPalette(gSecondaryPalette)))
return false;
*/
continued...
Code:
bool loadImages()
{
if(!_BACKGROUND_IMAGE_.load("stars.bmp"))
return false;
if(!_BACKGROUND_IMAGE_.setPalette(gPrimaryPalette)) // _BACKGROUND_IMAGE_ is my bitmap object.
return false;
/* If I comment this section out the program still works fine it appears
if(!_BACKGROUND_IMAGE_.setPalette(gSecondaryPalette)) // Set backbuffer surface palette to color table of my bitmap.
return false;
*/
if(!_BACKGROUND_IMAGE_.draw(gPrimarySurface))
return false;
if(!_BACKGROUND_IMAGE_.draw(gSecondarySurface))
return false;
return true;
}
... gPrimarySurface->Flip(NULL, DDFLIP_WAIT);
================================================== ======================
Second is about releasing attached surfaces.
- I thought I read somewhere that when you release a surface all of its attached surfaces are automatically released. Is this true? Code snippets I've seen explicitly release backbuffers.
Code:
case WM_DESTROY:
if(gDirectDrawObject != NULL)
{
if(gSecondarySurface != NULL) // <--- This is backbuffer attached to primary surface.
gSecondarySurface->Release(); // <--- These two lines needed?
if(gPrimarySurface != NULL)
gPrimarySurface->Release();
gDirectDrawObject->Release();
}
ShowCursor(true);
PostQuitMessage(0);
break;
================================================== =======================
Last question has to do with images used for a game.
- Is it true all images used in a game have to use the same palette? I've only drawn one image to the screen at a time so far (N00B, no sprites yet) and two images with different palettes = disaster unless I explicitly alter the primary surface palette before I display a new image. I'm just not sure how to go about making the game artwork if this is the case. What do you guys do? Make all of the artwork into one big file to ensure a common color table? I suck at drawing so I use 3D packages (3D studio max) so rendering = different color tables, no? (Photoshop CS2 = my 2D package).
================================================== =======================
thnx for any help