Getcolor query

Blitz3D Forums/Blitz3D Beginners Area/Getcolor query

keyboard(Posted 2004) [#1]
<edit>Blitz+
using <Graphics 320,240,16,0>
the following code returns 248,252,248
I expected 255,255,255
can anyone help me with why this happens?

using <Graphics 320,240,32,0>
it returns 255,255,255
but white is white in 16 bits, surely?

Graphics 320,240,16,0
SetBuffer BackBuffer() 
Color 255,255,255
Rect 10,10,100,100,1
GetColor 11,11
Text 10,200, " R:" + ColorRed() + " G:" + ColorGreen() + " B:" + ColorBlue() 
Flip  
WaitKey()
End 



Paulo(Posted 2004) [#2]
weird, i get 255,255,255 with 320,240,16,0 and 320,240,32,0


Rob Farley(Posted 2004) [#3]
It's a graphics card thing, the way 16 bits work

Some use the 16bits as 5,5,5 (15 bits) others use 6,5,5 or 5,6,5

Put the card into 32 bit mode and everything will work fine.

I wrote a little function that you can use to get the actual colour from a graphics card if you're in 16 bit mode...

http://www.blitzbasic.com/Community/posts.php?topic=37070#406787


JazzieB(Posted 2004) [#4]
To elaborate on what's just been said, the reason why you don't get 255 in 16 bit graphics mode is because only the highest bits are stored (5 or 6 depending on the card). 255 requires 8 bits.

255 = 11111111
248 = 11111000
252 = 11111100

The most common 16 bit mode is 565, which is 5 for red, 6 for green and 5 for blue: 5 + 6 + 5 = 16 bits.

24 and 32 bit graphics modes use all 8 bits to store each element (32 bit mode has an extra alpha channel as well as the normal red, green and blue channels).


keyboard(Posted 2004) [#5]
Put the card into 32 bit mode and everything will work fine.


light bulb lights up dimly ;)

thanks everybody, and the link to the function, Rob.


JazzieB(Posted 2004) [#6]
You shouldn't force graphics cards into a certain bitdepth. If you're planning on other people playing your games then you need to account for those people that may not have a card capable of 24/32 bit graphics. Probably not that many around here, but there will be plenty in the general public.

There are commands to check whether someone's card is capable of a certain screen resolution and bitdepth, but you can't simply tell those people with 16 bit cards that they can't play your game.

To get around it at the beginning of your code write the various colours you need to do a specific check for to a temp image (after graphics mode has been set). Then use GetColor to read it back and store in variables for use later. Then all you need to do is check for those stored values rather than hard-coding it.

For example in one of my early programs it wouldn't set the mask colour correctly when loading in sprites. So, I used the GetColor command to read the top left pixel of the animstrip knowing that this would be the mask colour. I then used this to set the right mask colour. Hence it now works in every bitdepth.

Hope that helps.


keyboard(Posted 2004) [#7]
cheers JazzieB, it does help ;)


wedoe(Posted 2004) [#8]
I made this snippet a long time ago, check it out, it will solve your problem:

http://www.blitzbasic.com/codearcs/codearcs.php?code=182


keyboard(Posted 2004) [#9]
Many thanks, Wedoe.