-
Is there a way...
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?
-
Member
Regular Contributor
Re: Is there a way...
-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).]
-
Senior Member
OpenGL Guru
Re: Is there a way...
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... 
Bob
-
Re: Is there a way...
I'll give that a try, thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules