-
A month or so ago in the Games & Graphics forum there was a question posted about changing colours on the screen by changing the palette entries. Basically they were saying you used to be able to do it in DOS and could you do it in DirectX? At least one respondent said that you could, and I thought I'd test it out but have had no luck so far.
The original question was VB-based, and I'm using C, so I didn't reply to the other thread. I just remembered it today though and thought I'd see if anyone had any idea how to do it. This is the code I'm using at the moment:
Code:
int Game_Main(void *parms = NULL, int num_parms = 0)
{
// this is the main loop of the game
// test if user is hitting ESC and send WM_CLOSE
if (KEYDOWN(VK_ESCAPE))
SendMessage(main_window_handle,WM_CLOSE,0,0);
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
lpddsprimary->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
int mempitch = ddsd.lPitch;
UCHAR *video_buffer = (UCHAR *)ddsd.lpSurface;
// Now rows and columns are accessed in the form
// video_buffer[row + column*mempitch]
static int doneonce = 0;
if (!doneonce)
{ for(int row=0; row<640; row++)
for(int column=0; column<480; column++)
video_buffer[row + column*mempitch] = rand() % 256;
doneonce = 1;
}
for(int colour=1; colour<255; colour++)
{
palette[colour].peRed = rand() % 256;
palette[colour].peGreen = rand() % 256;
palette[colour].peBlue = rand() % 256;
palette[colour].peFlags = PC_NOCOLLAPSE;
}
lpdd4->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 | DDPCAPS_INITIALIZE,
palette, &lpddpal, NULL);
lpddsprimary->SetPalette(lpddpal);
lpddsprimary->Unlock(NULL);
// return success or failure
return(1);
} // end Game_Main
-
Hmm.. I would have thought someone would at least have something to say on this. Surely someone out there knows what I'm talking about?
-
I'm sure someone around here knows how to use DirectDraw... why so quiet? Doesn't look like there's anything wrong with the code? Just completely stunned by my idiocy in writing this code? Speak up, I can see you sitting there with the mouse in your hand... don't you click that back button or close the window, reply first!
-
Okay well I've tried something a bit different (don't really know what I'm doing that well) which seems to have some effect, but doesn't work properly. It starts off with random colours, then changes the palette (which seems to work for a while) and then it just stops. Here is the code:
Code:
int Game_Main(void *parms = NULL, int num_parms = 0)
{
// this is the main loop of the game
// test if user is hitting ESC and send WM_CLOSE
if (KEYDOWN(VK_ESCAPE))
SendMessage(main_window_handle,WM_CLOSE,0,0);
static int done = 0;
if (done < 50)
{ memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
if(FAILED(lpddsprimary->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL)))
return(0);
int mempitch = ddsd.lPitch;
UCHAR *video_buffer = (UCHAR *)ddsd.lpSurface;
// Now rows and columns are accessed in the form
// video_buffer[row + column*mempitch]
for(int row=0; row<640; row++)
for(int column=0; column<480; column++)
video_buffer[row + column*mempitch] = rand() % 256;
if(FAILED(lpddsprimary->Unlock(NULL)))
return(0);
done++;
} else
{
for(int colour=1; colour<255; colour++)
{
palette[colour].peRed = rand() % 256;
palette[colour].peGreen = rand() % 256;
palette[colour].peBlue = rand() % 256;
//palette[colour].peFlags = PC_NOCOLLAPSE;
}
if(FAILED(lpdd4->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 | DDPCAPS_INITIALIZE,
palette, &lpddpal, NULL)))
return(0);
if(FAILED(lpddsprimary->SetPalette(lpddpal)))
return(0);
}
// return success or failure
return(1);
} // end Game_Main
So, any idea what I'm doing wrong?
-
Thanks, but that code is from an older version of a book I have already, in fact the code I posted was a modified version of a simpler example. I know how to use DirectDraw mainly, but I would like to know how you can change the palette to change the image on-screen.
-
Got it!
I have found the solution - the IDIRECTDRAWPALETTE::SetEntries() function. Was kinda obvious after all that :rolleyes:
I took out a bit of my code and added:
Code:
if(FAILED(lpddpal->SetEntries(0, 0, 256, palette)))
return(0);
and now it works fine :D
-
Hey, HarryW! I'm making a game in DX (in Visual Basic) and need a small DLL for the special effects to run faster...
I know C++ is much faster than VB even in a DLL, so could you please make me one with a very simple loop and only one instruction inside it? Please, I really need it! If you're interested, e-mail me!
-
-
Sorry Parksie, but I'm at school and can't see the DLL right now (I don't have WinZip here).
But I guess you wanna show me a DLL of yours! ;) Ok, if you want, thanks :)
On the other hand, it can be a DLL with effects you already made... hum... maybe I should stop guessing and go home to see it ;)