我需要在 OSG 中完全禁用纹理。我尝试glDisable(GL_TEXTURE_2D)
并使用了 osg::stateSet,但是一些具有纹理的节点仍然呈现它们的纹理。有没有办法全局关闭纹理?
一点背景知识:我需要为一个场景生成一个对象覆盖图,也就是说,知道是什么对象产生了每个可见像素。我用平面颜色渲染每个对象并读回颜色缓冲区 - 这就是为什么纹理会破坏我正在尝试做的事情。关于如何实现这一点的任何其他想法?
我需要在 OSG 中完全禁用纹理。我尝试glDisable(GL_TEXTURE_2D)
并使用了 osg::stateSet,但是一些具有纹理的节点仍然呈现它们的纹理。有没有办法全局关闭纹理?
一点背景知识:我需要为一个场景生成一个对象覆盖图,也就是说,知道是什么对象产生了每个可见像素。我用平面颜色渲染每个对象并读回颜色缓冲区 - 这就是为什么纹理会破坏我正在尝试做的事情。关于如何实现这一点的任何其他想法?
你确定在设置 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 将被忽略,但您可能处于知道不会发生这种情况的位置。
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 邮件列表?这似乎是一个更合适的地方问。
您使用的是 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()设置的根节点)