Skip to main content
GameDev.net gamedev.net
🔒 Locked

glReadPixels Question

Started by Geometrian Aug 2, 2007 at 2:31 PM 10 replies 1.3k views
Original Post
Geometrian
Geometrian
Hi, I'm trying to use glReadPixels() to get the color of a single pixel at coordinates (x,y). I checked the documentation, but I couldn't find anything. So, can someone give me a few lines of code that returns data=(red, green, blue)? Thanks, Geometrian
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]
dpadam450
dpadam450
What does your current function look like?
NBA2K, Madden, Maneater, Killing Floor, Sims 
Geometrian
Geometrian
I don't have one. I don't know how to make one, so that's my question.
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]
Geometrian
Geometrian
glReadPixelsb(x, y, 1, 1, GL_RGB) works. Thanks for looking, everyone.
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]
zedz
zedz
b == byte the -128->127 i think u perhaps want to use ub == unsigned byte which is 0->255
Geometrian
Geometrian
Where would I put that?
G
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]
Redien
Redien
Instead of glReadPixelsb(x, y, 1, 1, GL_RGB) use glReadPixelsub(x, y, 1, 1, GL_RGB). :)
Geometrian
Geometrian
I see, but why would it make a difference?
G
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]
Redien
Redien
When you use the glReadPixelsb(x, y, 1, 1, GL_RGB) function it returns an array of signed bytes. I.E. the byte has a both positive and negative side ranging from -128 to 127 as mentioned before. But since standard RGB values range from 0 to 255 you would want to use the function that returns unsigned bytes which also range from 0 to 255.
Geometrian
Geometrian
That's weird, the function works exactly as it should, perhaps because I'm using Python?
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]
Redien
Redien
I don't know how your code looks like. But the bytes probably gets casted into unsigned bytes anyway when you store them.

IMHO, you should use glReadPixelsub(x, y, 1, 1, GL_RGB) anyway since it's probably unsigned bytes you want.
Geometrian
Geometrian
OK, will change that.
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.