Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to use glReadPixels() to select object in the scene. I gave every object in the scene a different color, but when I use the gluLookAt function to change the view, the glReadPixels() can not get the right color of the object my mouse click, Why? If I don't move,It can select the object my mouse click.:confused::confused:
I find that when I move the view,I click mouse at the same at same spot,then the object is selected which was I didn't move view before.
The object selected is not the object which my mouse click now.:confused:
Posted
Updated 16-Jun-10 16:55pm
v4

1 solution

In windows (I'm assuming your using windows) the origin (0,0) is at the top left of the screen, but with glReadPixels the origin is at the bottom left so you may have to adjust the mouse coords before you use them with the function.

Also you may want to do something more like this:
Picking Tutorial[^]

It's more effort but it would allow you to pick between objects of the same colour.
 
Share this answer
 
Comments
thundersun 15-Jun-10 9:08am    
Thanks,I have already changed the coords,this is the code:
glReadPixels(point.x, iViewPort[3]-point.y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &fdepth);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900