Advertisement

16Bit Color

Started by February 24, 2000 08:00 AM
4 comments, last by Blake 24 years, 6 months ago
I''m using 16bit color in my DirectX game. I sometimes need to lock the surface and draw directly to it (lines and pixels) which work just great on my machine. But when I take my program over to a different computer, the colors come out all wrong... What''s the deal here and how do I fix it? I''m using the macro: (in pseudo code) RGB16BIT (r,g,b) ( b%32 + (g%32 << 5) + (r% 32 << 10)) And using it on something like: WORD pixel = RGB16BIT (0,255,0); //Which should be green! Like I said, I get green on my machine but on another I get dark blue. HELLLLPPP!
You have to check the pixel format for the surface because in 16 bit color it can be 555 or 565. The algorithm you have there is for a 555 surface. For a 565 surface you would have to make another macro:

RGB16BIT565(r,g,b) ((b&31) + ((g&63) << 5) + ((r&31) << 11)))

Then you do your blit according to the surface format. You can get the surface format with GetPixelFormat(LPDDPIXELFORMAT lpddpf);

(You could also do the macro like your other one)
RGB16BIT565(r,g,b) (b%32 + ((g%64) << 5) + ((r%32) << 10))

Edited by - lshadow on 2/24/00 8:20:09 AM
Working on: DoP
Advertisement
Thanks so much for your help, but I still need to know one thing:

I took a look at the LPDDPIXELFORMAT class and there are multitudes of member variables. Which one do I need to check to see if the 555 or 565 format is being used?

Blake
I think you just need to check the value of the green mask. If you run through debug, you can see all of the values for the structure. I think the green mask should say 6 if its 5-6-5 if I remember correctly.

Still Learning...
Still Learning...
Strange.... After doing this:

DDPIXELFORMAT ddpf;
//ZeroMem ddpf;
BackBuffer->GetPixelFormat(&ddpf)

the colors come out correctly on both computers now. I''m not checking for any certain color value. I''m really confused now though I''m glad that it appears to work. I''m worried that it still may not work on other video cards though.

Blake
Ok, here''s how it works:

int PixelFormat; //Flag for keeping track of format
DDPIXELFORMAT ddpf; //Pixel Format object

ddpf.dwSize = sizeof(ddpf); //Init object

//Create DirectX Object, SetDisplayMode, Create Primary
//and BackBuffer, Load Images blah blah blah

BackBuffer->GetPixelFormat(&ddpf);

if (ddpf.dwGBitMask == 0x000003E0) //555
PixelFormat = 1;
else if (ddpf.dwGBitMask == 0x000007E0) //565
PixelFormat = 2;
else if (ddpf.dwGBitMask == 0x000000F0) //Alpha Channel???
PixelFormat = 3;
else
PixelFormat = 0; //Unknown, unused

Hope that helps! It''s working great for me.

Blake

This topic is closed to new replies.

Advertisement