在 OpenSceneGraph 中禁用纹理
我需要完全禁用 OSG 中的纹理。 我尝试了 glDisable(GL_TEXTURE_2D)
并使用了 osg::stateSet,但一些具有纹理的节点仍然渲染其纹理。 有没有办法全局关闭纹理?
一点背景知识:我需要为场景生成一个对象覆盖图,即知道哪个对象产生了每个可见像素。 我用平面颜色渲染每个对象并读回颜色缓冲区 - 这就是纹理破坏我想要做的事情的原因。 关于如何实现这一目标还有其他想法吗?
I need to completely disable texturing in OSG. I tried glDisable(GL_TEXTURE_2D)
and also using an osg::stateSet, but some nodes that have textures still render their textures. Is there any way to globally turn off texturing?
A bit of background : I need to produce an object coverage map for a scene, that is, knowing what object produced each visible pixel. I'm rendering each object with a flat color and reading back the color buffer - this is why texturing breaks what I'm trying to do. Any other ideas about how to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否确保在设置Texture2D属性时设置了osg::StateAttribute::OVERRIDE位? 即类似于
其中
ss
是场景图中足够高的节点上的状态集,以包含可能具有纹理的所有事物。当然,如果 GL_TEXTURE_2D 模式或任何下方的 Texture2D 属性设置了 osg::StateAttribute::PROTECTED 位,则 OVERRIDE 将被忽略,但您可能处于知道这种情况不会发生的位置。
Did you make sure to set the osg::StateAttribute::OVERRIDE bit when setting the Texture2D attribute? i.e. something like
where
ss
is a stateset on a node high enough up in your scene graph to encompass all things that might have textures.Of course if the GL_TEXTURE_2D mode or any Texture2D attributes lower down have the osg::StateAttribute::PROTECTED bit set then the OVERRIDE will be ignored but you might be in a position where you know that's not going to happen.
您遇到问题的原因可能是某些节点使用 osg::StateAttribute::OVERRIDE,就像 Troubadour (正确地)建议您应该这样做。 假设是这种情况,您可以创建一个节点访问者,它实际上遍历整个树并关闭纹理渲染 - 非常粗糙,但会起作用。
至于你问题的第二部分:一个选择是使用 OSG 中已经内置的函数来进行相交 - 将光线从眼睛投射到屏幕上的每个像素,然后查看它相交的位置 - 非常慢,但适用于当然 :)
还有 openGL 选择模式(虽然我不得不说我自己从未使用过它,所以我不知道它使用起来有多复杂) - 你可以阅读它
此处: http://www.opengl.org/resources/faq/technical/selection .htm
The reason you are having problems is probably that certain nodes use osg::StateAttribute::OVERRIDE, like Troubadour (rightly) suggested you should. Assuming that's the case, you can create a a node visitor that actually traverses the entire tree and shuts off texture rendering - very crude, but will work.
As for the second part of your question: One option is to use the already built in functions in OSG for intersections - cast a ray from the eye to each pixel on the screen, and see where it intersects - VERY slow, but will work for sure :)
There's also the openGL select mode (though I have to say I've never used it myself so I don't know how complicated it is to use) - you can read about it
here: http://www.opengl.org/resources/faq/technical/selection.htm
您是否考虑过将您的问题发布到 OSG 邮件列表? 这似乎是一个更合适的提问地点。
Have you considered posting your question to the OSG mailing list? That would seem like a much more appropriate place to ask.
您使用的是 osgViewer::Viewer (单一/默认查看器)还是 osgViewer::View? 如果 osgGA::StateSetManipulator 已使用 addEventHandler() 添加,则“t”键可切换纹理。
最终,被调用的是void StateSetManipulator::setTextureEnabled(bool newtexture)。
它的作用是:
其中*_stateset*是一个高层节点(例如在Viewer/View->setSceneData()处设置的根节点)
Are you using osgViewer::Viewer (the single/default viewer) or a osgViewer::View? The 't' key toggles texturing in those if osgGA::StateSetManipulator has been added with addEventHandler().
Eventually, what gets called is void StateSetManipulator::setTextureEnabled(bool newtexture).
What it does is:
Where *_stateset* is a high up node (e.g. the root node set at Viewer/View->setSceneData())