Help with avoiding 16-bit color corruption?

Started by
2 comments, last by Ninjan 24 years, 8 months ago
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

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.

Get off my lawn!

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

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

Ninjan

This topic is closed to new replies.

Advertisement