ReadPixel working in windowed mode but not fullscr

Blitz3D Forums/Blitz3D Beginners Area/ReadPixel working in windowed mode but not fullscr

Dax Trajero(Posted 2004) [#1]
Both ReadPixel and ReadPixelFast are working fine in windowsed mode but return the wrong values when working in fullscreen mode

In fact, the values returned in fullscreen mode don't correspond at all with any colours used on the .png file at all.

The colour should be FF005F1C
The colour returned os FF005C18

I've checked the x,y values and these are fine

Any ideas ?


Ross C(Posted 2004) [#2]
Try putting the buffer in the readpixel commands. Even though it's optional, it sometimes doesn't use the correct buffer.


Dax Trajero(Posted 2004) [#3]
I'm already doing this

I lock the buffer
then I readpixelfast
I unlock the buffer


Yan(Posted 2004) [#4]
I'm guessing you're using a 32/24bit desktop (windowed mode always uses the desktop colour depth) and a 16bit screen mode.

This is normal behaviour and is to do with the way 16bit modes are handled by video cards.

I'm rubbish at explaining this kind of thing. So I'm not going to bother trying. ;o)

I'm sure someone will be along in a bit to explain properly. :o)


Yan


Dax Trajero(Posted 2004) [#5]
could I correct myself

the correct value is returned in debug mode (windowed)
the incorrect value is returned in fullscreen mode


Dax Trajero(Posted 2004) [#6]
the image in question is just a 512 x 384 x 8 image


Dax Trajero(Posted 2004) [#7]
YAN you're right - it works for 32bit graphics mode, but not for a 16bit graphics mode

why is that ?


Dax Trajero(Posted 2004) [#8]
looking at the readpixelfast command it says it returns Alpha, Red,Green,Blue components of the pixel

These 4 compents are each a byte in size aren't they ? Meaning readpxielfast only works on 32bit colour ?

Is this true ?


Yan(Posted 2004) [#9]
Okay...I'll try to explain, but you were warned! ;o)

When the video card converts a 32bit image to 16bits the two most common methods are:

1)The lowest 3bits are chopped off the end of each of the red, green and blue values (giving 15bits). The so called 555 format.

2)The lower 3bit of the red and blue and the lower 2 bits of the green are chopped off (giving 16bits). The so called 565 format.

The combined values are then slapped into the required 16bits (the 555 format doesn't use the top bit).


So, when Blitz reads a 16bit value it's really returning...

(8 bits red AND $F8) for red
(8 bits blue AND $F8) for blue
(8 bits green AND $F8/$FC) for green (depending on the video card)


I do believe 565 is the most common mode used.

BTW, $5F AND $FC is $5C so it seems your card uses 565.


Yan


Yan(Posted 2004) [#10]
When I say 8 bits red etc. I'm reffering to the original 24bit image.


Yan


Dax Trajero(Posted 2004) [#11]
Thanks YAN

That explanation was fine :)

Ideally I want the prgram to choose what mode it uses eg. graphicsmode 640,480,0

I could use colours that aren't affected by this "trimming" I suppose, but whats the best work-around for this problem ?


Yan(Posted 2004) [#12]
You could just always use the 555 format...
rgb = ReadPixelFast( 0, 0, buffer) And $00F8F8F8
That SHOULD give you consistent results accross all hardware and bit depths.

In your example above. You should always get $005818 regardless of video card and bitdepth.


YAN


Dax Trajero(Posted 2004) [#13]
ok, thanks - thats been a good learning experience for me.

With it being my first game, its the first time I've come across this situation. I suppose with a bit more thought I should've realised!

thanks again,
-Dax