|
-
Dec 20th, 2000, 10:51 AM
#1
Thread Starter
Frenzied Member
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
Harry.
"From one thing, know ten thousand things."
-
Jan 2nd, 2001, 01:45 PM
#2
Thread Starter
Frenzied Member
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?
Harry.
"From one thing, know ten thousand things."
-
Jan 5th, 2001, 09:47 PM
#3
Thread Starter
Frenzied Member
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!
Harry.
"From one thing, know ten thousand things."
-
Jan 5th, 2001, 11:30 PM
#4
Thread Starter
Frenzied Member
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?
Harry.
"From one thing, know ten thousand things."
-
Jan 7th, 2001, 06:56 PM
#5
Thread Starter
Frenzied Member
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.
Harry.
"From one thing, know ten thousand things."
-
Jan 8th, 2001, 10:25 PM
#6
Thread Starter
Frenzied Member
Harry.
"From one thing, know ten thousand things."
-
Jan 12th, 2001, 07:20 PM
#7
Frenzied Member
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!
-
Jan 12th, 2001, 07:47 PM
#8
Monday Morning Lunatic
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 16th, 2001, 12:01 PM
#9
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|