Use glreadpixels to query data

Hello,

I have built 3D plots using openGL. Now, I would like to include a function so that the user can query the data based on it’s color.

I was trying to use glReadPixels to query the color (RGB) using the position of the mouse and then convert this color back to the value according to the color scale. Example:

pPixelData = (float *) calloc(3, sizeof(float));

// Copy the area under the mouse cursor
glReadPixels(mx, my, 1, 1, GL_RGB, GL_FLOAT, pPixelData);

The problem is that when I do this the color is diferent from the scale due to lighting effects. My question is:

a) can I use glReadPixels to capture the color (in RGB format) without the influence of lighting?

OR

b)do I have to render the whole 3D plot first with lighting disabled and then use glReadPixels?

I would prefer to use a) if possible.

ib/ u need to turn off lighting first

a)no
b)yes

However, I recommend avoiding glReadPixels (and GetTex(Sub)Image for that matter) at all costs, whenever possible.

I’m not sure what exactly your “3D plots” look like. If there’s any form of occlusion going on, it will become difficult, but if it’s, say, a simple function graph, you should be able to resolve the question “is this mouse position on the graph?” with some algebra.

I know that a function to retreive the value of the data would be more effective and accurate. But on the other hand I want a function that can work with any kind of 3D surface plot, vector plot, contour plot, etc.

I ask this because I have seen this in commercial software and I wonder how it is done. Maybe it is ray casting, intersection with the objects and interpolation of the value.