and then you want to know what the pixel value is at a specific x/y position?
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.
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:
How do I define the pointer??
Is the x-Positon, y-Position in my local OpenGLWindow (created with glutCreateWindow) or in absolute screen-coordinates??
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)