如何使用glReadPixels选择场景中的对象? [英] How can I use glReadPixels to select object in the scene?

查看:80
本文介绍了如何使用glReadPixels选择场景中的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用glReadPixels()选择场景中的对象.我为场景中的每个对象赋予了不同的颜色,但是当我使用gluLookAt函数更改视图时,glReadPixels()无法获得我鼠标单击的对象的正确颜色,为什么?如果我不动,它可以选择鼠标单击的对象.:confused :: confused:
我发现当我移动视图时,我在同一位置单击鼠标,然后选择了我之前没有移动过视图的对象.
选定的对象不是我的鼠标现在单击的对象.:confused:

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:

推荐答案

在Windows中(假设您使用的是Windows)是原点(0, 0)位于屏幕的左上方,但是使用glReadPixels时,原点位于左侧的底部,因此在将鼠标坐标与该功能配合使用之前,可能必须先对其进行调整.

另外,您可能想做更多类似的事情:
选择教程 [ ^ ]

这样做比较省力,但可以让您在相同颜色的对象之间进行选择.
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.


这篇关于如何使用glReadPixels选择场景中的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆