Results 1 to 4 of 4

Thread: Value of Pixel (Color) on Mouse Position

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2005
    Posts
    20

    Value of Pixel (Color) on Mouse Position

    How can one read in the value of a Pixel on the mouse Position?

    The Pixels get its Value with :

    Pixels[x][y][0]=value // 0..255; Red component
    Pixels[x][y][1]=value // 0..255; Green component
    Pixels[x][y][2]=value // 0..255; Blue component

    glDrawPixels(...blabla,...GL_RGB_,..., Pixels));

    These values (one at the time)I want to read back, with the mouse pointer.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Jan 2004
    Posts
    314

    Re: Value of Pixel (Color) on Mouse Position

    Errr... Let me get this straight:
    1. you're writing a bitmap to the frame buffer
    2. and then you want to know what the pixel value is at a specific x/y position?
    3. and you actually want to use OpenGL for that?

    If you're not too worried about readback speed, you can read the framebuffer using glReadPixels.

    You then get the mouse x/y positions and use those as the indices to read back the pixel value.

    But if you're interested in just picking from a bitmap that you have just written to the framebuffer, you can skip the readpixels and index straight into your Pixels array.

    Determining what the X/Y position is depends on what windowing system or API you're using.
    With GLUT it seems to use some callback functions specifically for the mouse (glutMouseFunc ,glutMotionFunc ,glutPassiveMotionFunc )

    With Windows and X windows, there will be a general event callback function (also used for keys, window resizes etc etc).

    The only thing you're going to have to worry about is maybe reversing the Y-axis, and that depends on whether or not glDrawPixels draws everything upside down.

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2005
    Posts
    20

    Re: Value of Pixel (Color) on Mouse Position

    Right, I have an array with data-salat I visualize on the screen. Then I want to pic a little piece an look if it is an onion, tomato or tuna. So I need the value of that Pixel. And yes, I want to use OpenGL.

    I am playing with glReadPixels right now, but I am confused. If I want to read one pixel I declare:

    glReadPixels(x-Position,y-Position,1,1,GL_RGB_GL_BYTE_*ThePointer);

    How do I define the pointer??
    Is the x-Positon, y-Position in my local OpenGLWindow (created with glutCreateWindow) or in absolute screen-coordinates??

  4. #4
    Senior Member Regular Contributor
    Join Date
    Jan 2004
    Posts
    314

    Re: Value of Pixel (Color) on Mouse Position

    With normal windowing systems, mouse X and Y are relative to the "client area" - the top left of the inside of the window, excluding the window borders.

    I kind of assume that's the same with glut.
    You can, of course, test it: just use the glutMouseFunc to print the mouse coordinates when the mouse is clicked. Do it with a small window on the right side of the screen.
    If you get large X values, it's screen-absolute, if they're small, it's window-relative.

    I don't know if the Y values with glut would be 0 at the bottom or at the top. You may have to reverse the Y coordinate - something like py=(height-1-my)

Similar Threads

  1. How to get a ray vector at the mouse position?
    By dotrana in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 08-27-2013, 06:00 PM
  2. get current mouse position's color
    By dousti91 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-03-2013, 09:13 AM
  3. Decide a pixel's color based on its position?
    By firegun9 in forum OpenGL: GLSL
    Replies: 2
    Last Post: 10-15-2009, 02:24 PM
  4. How to get the mouse position ?
    By in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 01-01-2003, 08:05 PM
  5. Mouse Position
    By SeeDAreW in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-05-2002, 11:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean