PDA

View Full Version : how to use glReadPixels for a single pixel



pjhancoc
03-18-2003, 06:43 AM
Hi,
Im wanting to store the RGB value, in three seperate variables, of the pixel on the screen where the mouse was clicked. Presumably the best way to do this is use glReadPixels. Could anyone give me a couple of lines of code I could use to store the RGB. Thanks.

JustHanging
03-18-2003, 08:33 AM
float color[3];
glReadPixels(x, y, 1, 1, GL_RGB, GL_FLOAT, color);
r=color[0];
g=color[1];
b=color[2];

In opengl the y-axis is reversed, so you have to set
y=(height of the window's client area)-y;

-Ilkka