在 OpenSceneGraph 中禁用纹理

发布于 2024-07-13 21:48:30 字数 238 浏览 5 评论 0原文

我需要完全禁用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

别理我 2024-07-20 21:48:30

您是否确保在设置Texture2D属性时设置了osg::StateAttribute::OVERRIDE位? 即类似于

osg::Texture2D*const tex2D = new osg::Texture2D;
ss->setAttributeAndModes( tex2D, osg::StateAttribute::OFF | 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

osg::Texture2D*const tex2D = new osg::Texture2D;
ss->setAttributeAndModes( tex2D, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE );

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.

风铃鹿 2024-07-20 21:48:30

您遇到问题的原因可能是某些节点使用 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

物价感观 2024-07-20 21:48:30

您是否考虑过将您的问题发布到 OSG 邮件列表? 这似乎是一个更合适的提问地点。

Have you considered posting your question to the OSG mailing list? That would seem like a much more appropriate place to ask.

洛阳烟雨空心柳 2024-07-20 21:48:30

您使用的是 osgViewer::Viewer (单一/默认查看器)还是 osgViewer::View? 如果 osgGA::StateSetManipulator 已使用 addEventHandler() 添加,则“t”键可切换纹理。

最终,被调用的是void StateSetManipulator::setTextureEnabled(bool newtexture)
它的作用是:

unsigned int mode = osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF;
for( unsigned int ii=0; ii < 4; ii++ )
{
    _stateset->setTextureMode( ii, GL_TEXTURE_1D, mode );
    _stateset->setTextureMode( ii, GL_TEXTURE_2D, mode );
    _stateset->setTextureMode( ii, GL_TEXTURE_3D, mode );
    _stateset->setTextureMode( ii, GL_TEXTURE_RECTANGLE, mode );
    _stateset->setTextureMode( ii, GL_TEXTURE_CUBE_MAP, mode);
}

其中*_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:

unsigned int mode = osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF;
for( unsigned int ii=0; ii < 4; ii++ )
{
    _stateset->setTextureMode( ii, GL_TEXTURE_1D, mode );
    _stateset->setTextureMode( ii, GL_TEXTURE_2D, mode );
    _stateset->setTextureMode( ii, GL_TEXTURE_3D, mode );
    _stateset->setTextureMode( ii, GL_TEXTURE_RECTANGLE, mode );
    _stateset->setTextureMode( ii, GL_TEXTURE_CUBE_MAP, mode);
}

Where *_stateset* is a high up node (e.g. the root node set at Viewer/View->setSceneData())

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文