Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Is there a way...

  1. #1
    Intern Contributor
    Join Date
    Feb 2000
    Location
    Stafford, UK
    Posts
    60

    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?

  2. #2
    Member Regular Contributor
    Join Date
    Feb 2000
    Location
    milano, italy
    Posts
    282

    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).]
    Dolo/\/\ightY

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,982

    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

  4. #4
    Intern Contributor
    Join Date
    Feb 2000
    Location
    Stafford, UK
    Posts
    60

    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
  •