Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ninjan

Help with avoiding 16-bit color corruption?

This topic is 6891 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am guessing you are using DirectX? If so, here is what I know.
Use the DD function GetPixelFormat() to get info about the pixel format
of your screen. For example:


DDPIXELFORMAT ddpf;

ZeroMemory( &ddpf, sizeof(DDPIXELFORMAT) );
ddpf.dwSize = sizeof(DDPIXELFORMAT);

if(primary_surface->GetPixelFormat(&ddpf) != DD_OK )
return 0;

This will get the info you want stored in the ddpf struct.
Assuming primary_surface is your main screen.


If your video card supports a 555 format, you will see the
ddpf struct members set like this:

ddpf.dwRBitMask equals 0x7C00
ddpf.dwGBitMask equals 0x03E0
ddpf.dwBBitMask equals 0x001F

and the 565 format would look like this:

ddpf.dwRBitMask equals 0xF800
ddpf.dwGBitMask equals 0x07E0
ddpf.dwBBitMask equals 0x001F


Hope that helps.

-Tank2k

Share this post


Link to post
Share on other sites
Advertisement
you cant always count on pixel formats, especially 555 and 565, but also 888.

sometimes r and b get switched, and you wind up with a bgr mode.

Share this post


Link to post
Share on other sites
Hello.

I'm working on implementing 16-bit color into my 2D game. The only problem is that if I use this code to build a 16-bit color value,

#define _RGB16BIT(r,g,b) ((b%32) + ((g%32) << 5) + ((r%32) << 10))

I get bad color corruption on cards that use 6 bits for the green value. The code above works fine for cards that use 5 bits for each RGB value (like the ATI Rage Pro). So to fix it for cards that use 6 bits for the green value (like the TNT), we go like this:

#define _RGB16BIT(r,g,b) ((b%32) + ((g%32) << 6) + ((r%32) << 11))

The problem is that I think if I use the new code with cards that support only 5 bits for the green value, the colors will probably get screwed up on that.

Does anybody know of a way to find out what bit patterns a particular video card supports with code so that I can use the correct RGB values at runtime? Some Win32/DirectX/VESA query possibly?

Thanks,

Ninjan

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!