Getting color of position on screen?

BlitzMax Forums/BlitzMax Beginners Area/Getting color of position on screen?

chimaera(Posted 2009) [#1]
Is there a function to grab a color at a certain coordinate on screen without using grabpixmap and then evaluate its color?

I am messing around with a classic snake game and want check for collision without the use of images. Currently all art is drawn using drawoval without cls.

Hope anyone can help out.


xlsior(Posted 2009) [#2]
Currently all art is drawn using drawoval without cls.


Just a heads up: This won't work on all computers.

- On some, it will work perfectly (including yours, apparently)
- On some, you'll get really annoying flicker (many videocards double, tripple, or even quad-buffer the screen, so the next frame after a flip may not be the same as the last, but essentially 'rewind' a few frames first, which results in a flickering mess in the areas that you have movement going on.
- On some, you're going to see random garbage -- the OpenGL specs specifically mention that you cannot depend on the existing graphics surviving a flip, and need to redraw for compatibility sake.

Expect even more problems if you alt-tab away from the game for a moment, after which the existing graphics context may be erased and re-created (without all the 'old' drawings.

If you are creating a game just for fun or personal use, this may be a non-issue... but if you intent to share it with others (or even sell it), you are pretty much guaranteed to run into weird issues like those mentioned above... the only way to ensure it works on all computers, is to redraw the screen in its entirety each frame.... which in turn unfortunately raises the minimum video adapter requirements a little.


chimaera(Posted 2009) [#3]
Thanks for the advice.

I changed how this is treated a few hours later so that it now uses cls and redraws everything.

But I am still interested if there is a "Getpixelcolor" from screen on a specific coordinate, or if I have to do a grabpixmap and evaluate it myself.


ImaginaryHuman(Posted 2009) [#4]
If you don't mind OpenGL only, see glReadPixels() ... you can read a single pixel into a variable.