0
votes

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?

4

4 Answers

1
votes

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.

1
votes

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

0
votes

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

0
votes

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())