PDA

View Full Version : Is there a way...



David
03-09-2000, 06:57 AM
Im using glut, is there a way I can click on the screen, and get the RGB value of the pixel that I clicked on?

dmy
03-09-2000, 08:38 AM
-obtain the mouse location in window coordinates (pixels)

-use glReadPixels():

byte pixel[3];

glReadPixels(
mouse.x,mouse.y,
1,1,
GL_RGB,
GL_UNSIGNED_BYTE,
pixel
);

pixel[] will hold your pixel color

note that XXXpixels() functions are a bit slow...

Dolo/\/\ightY


[This message has been edited by dmy (edited 03-09-2000).]

Bob
03-09-2000, 08:41 AM
Hello

You can use void glReadPixels( GLint x,GLint y,GLsizei width,GLsizei height,GLenum format,GLenum type,GLvoid *pixels )

Used with void glutMouseFunc(void (*func)(int button, int state, int x, int y)) you can do like this.

mousefunc(int button, int state, int x, int y))
{
GLfloat pixel[4];
if(button==GLUT_LEFT_BUTTON)
{
glReadPixels(x, y, 1, 1, GL_RGB, GL_FLOAT, &pixel);
}
}

Before you call glutMainLoop() you have to call glutMouseFunc(mousefunc)

Everytime you press the left button on the screen, you will get the rgb values in the variable pixel.

Might not work that well since I'm not able to try it out right now... http://www.opengl.org/discussion_boards/ubb/tongue.gif

Bob

David
03-09-2000, 10:17 AM
I'll give that a try, thanks. http://www.opengl.org/discussion_boards/ubb/biggrin.gif