Masks and 16 bit colour

BlitzMax Forums/BlitzMax Beginners Area/Masks and 16 bit colour

Simon S(Posted 2005) [#1]
I learned the hard way about the odd way graphics card have to deal with 16 bit colour, and that feeding the true r,g,b value to setmaskcolor is asking for trouble.

I thought I'd use the method I used in B2/B+ to solve it. Write the pixel and read it back. Initial confusion was quickly solved when I realised pixmaps are always 32bit regardless of screen depth. So I wrote to the backbuffer, grabbed it, tested the pixel.

Sure enough the r,g,b returned is different in 16bit, but when I set my mask to the value I've just readpixelled from the back buffer I get a very odd effect. Observe...

The orignal image:


The 32 bit grab (Appears as I expect it to)


The 16 bit grab


Very strange. Feel free to check the original image, that odd pattern in the mask isn't down to some bizarre hatching I stuck in the background.

Any ideas folks?


JazzieB(Posted 2005) [#2]
Not sure about that hatching, very bizarre.

When I use colour for the mask I always have my program read in the pixel colour from a pixel that I know will only contain the mask colour.

However, what I like to do now is save my images in PNG format with alpha and set the blend mode to alpha when drawing them. No need to worry about a mask colour, plus you can get nice alpha-blended edges too.


ImaginaryHuman(Posted 2005) [#3]
It might be that your graphics card is set up to apply dithered output when in 16-bit mode, so your might be seeing a dithered display. It may be trying to represent the background color using a dither pattern?


Simon S(Posted 2005) [#4]
Been through the graphics options, certainly the default control panel options mention nothing about dithering 16 bit graphics. It is a new graphics card though (Radeon 9800) so I'm not entirely familiar with everything it does.

JazzieB your suggestion was excellent, those alpha blended edges look fantastic. Thanks for the advice, guess I can stop worrying about the confusing dither options.


ImaginaryHuman(Posted 2005) [#5]
Dithering is an option in OpenGL and may or may not be supported by the graphics hardware itself. There is an option to turn it off - a standard OpenGL command, but I forgot what it is.