Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Help with avoiding 16-bit color corruption?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Ninjan   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 September 1999 - 12:50 PM

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


Sponsor:

#2 Tank2k   Members   -  Reputation: 122

Like
Likes
Like

Posted 08 September 1999 - 07:55 PM

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


#3 TANSTAAFL   Moderators   -  Reputation: 1152

Like
Likes
Like

Posted 09 September 1999 - 07:13 AM

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.


#4 Ninjan   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 September 1999 - 12:50 PM

Thank you very much both of you for all your advice. It was exactly what I was looking for.

Ninjan





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS