Results 1 to 9 of 9

Thread: DDraw & Palettes

  1. #1

    Thread Starter
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827

    Question

    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."

  2. #2

    Thread Starter
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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."

  3. #3

    Thread Starter
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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."

  4. #4

    Thread Starter
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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."

  5. #5

    Thread Starter
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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."

  6. #6

    Thread Starter
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827

    Lightbulb Got it!

    I have found the solution - the IDIRECTDRAWPALETTE::SetEntries() function. Was kinda obvious after all that

    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
    Harry.

    "From one thing, know ten thousand things."

  7. #7
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    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!

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  9. #9
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width