Getting Colours from Read Pixel

Blitz3D Forums/Blitz3D Beginners Area/Getting Colours from Read Pixel

Cancerian(Posted 2005) [#1]
Hi,

I am having some strange results from the Read Pixel command and I was hoping someone could help me.

Basically what I have is a fullscreen JPEG image as the background and sprites falling from the top of the screen and bouncing off objects in the background image. The collision check with the background is simply to use Read Pixel to get the colour value of the background at the falling object's location. Anything other than pure white results in a collision.

The problem is that different computers produce different values as the Read Pixel result. On my test computer, white comes back as something like "-65000", so I set the check for any values less than that. However other computers give completely different results and the sprites are bouncing off the white background that they are supposed to pass through.

Basically, I'd like to know how to extrapolate the RGB value of the pixel from whatever Read Pixel is spitting out. Also, are there any known issues of different video cards producing wildly different color values - even if they are set to the same resolution and bitrate?

Thanks for any help or advice!


cermit(Posted 2005) [#2]
I dont think you should use a jpeg image for collision check (the pixels get wierd when jpeg is compressed), try with bmp or png you might get better results.
If you're still having trouble post some code, it'll be easier to see what the problem is.


Cancerian(Posted 2005) [#3]
I found the source of the problem! Ends up the other test computers had their desktops set to 16bit mode and I had only tested running the game in a window. When run at fullscreen (where I set the value to 32bit in Blitz) the effect works fine.

So I guess I have to find a value that will work whether the game is running in 16bit or 32bit - hence the need to break it down into RGB values. Regardless of bitdepth, white is always RGB 255,255,255 right?

Here's a paraphrased version of my code:

DrawImage background,0,0
LockBuffer BackBuffer()

;Cycle through each of the active objects
For object.object = Each object

;Check the background pixel for anything other than white.
bg_check = ReadPixel(object\x_pos,object\y_pos)

;If another color is detected, create a bounce effect
If bg_check < -66000
     ;Collision bounce code goes here
EndIf

;Unlock the backbuffer from the collision checks
UnlockBuffer BackBuffer()



TomToad(Posted 2005) [#4]
It might me easier to use a 256 greyscale mask image. Basically, you load and display the background image normally, but you load another image which isn't displayed with white as normal sections and black lined up to the obstructions, then you check colisions on the mask instead of the 32 bit color image. You can also use various shades of grey to identify the degree of obstruction, for instance white = roads, light grey = dirt paths, med grey = swamps, black = boulders, etc...


chris_b(Posted 2005) [#5]
Just store whatever ReadPixel returns for a white pixel in a variable before you start your main game loop.

eg:

global white%
color 255,255,255
plot 0,0
white=ReadPixel(0,0)

and then compare bg_check to your "white" variable


jfk EO-11110(Posted 2005) [#6]
The most significant byte of the long integer that is returned by readpixel may be a random value (AFAIK). since you won't need that byte anyway, I'd suggest to mask it out from beginning on:

rgb=ReadPixel(0,0) And $FFFFFF