[osg-users] Node needs to render at least one pixel

Tessier, Philip Philip.Tessier at ngc.com
Tue Jul 22 13:23:09 PDT 2008


A code extract is worth a thousand words...

* * *

OSG_LIBRARY_API osg::Geode* OSG_Library::createSquare(const osg::Vec3& corner,const osg::Vec3& width,const osg::Vec3& height, osg::Image* image)
	// set up the Geometry.
	osg::Geometry* geom = osg::createTexturedQuadGeometry(corner,width,height);
	osg::Texture2D *tex = new osg::Texture2D;
	tex->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_BORDER );
	tex->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_BORDER );

	osg::Geode* geode = new osg::Geode;
	geode->getOrCreateStateSet()->setMode( GL_NORMALIZE, osg::StateAttribute::ON );
	geode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OVERRIDE | osg::StateAttribute::OFF);

	return geode;

* * *

	else // not a_generateViewerScene
			osg::ref_ptr<osg::MatrixTransform> imageTransform = new osg::MatrixTransform();

			osg::ref_ptr<osg::Image> image = GetIntensityImage();

			float bmX_m = 0.01f * (float)Laser_GetXWaist();
			float bmY_m = 0.01f * (float)Laser_GetYWaist();

			osg::ref_ptr<osg::Geode> square = OSG_Library::createSquare(
				osg::Vec3( -0.5f * bmX_m, -0.5f * bmY_m,  0.0f),
				osg::Vec3(         bmX_m,          0.0f,  0.0f),
				osg::Vec3(          0.0f,         bmY_m,  0.0f),

			square -> setCullingActive( false);

			osg::Drawable * drawable = square ->getDrawable( 0);

			drawable -> setCullCallback( new DoNotCull());

			imageTransform -> addChild( square.get());

			imageTransform -> setCullingActive( false);

			// Turn off lighting so it always looks bright
			imageTransform ->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OVERRIDE | osg::StateAttribute::OFF);

			laserMatrixTransform -> addChild( imageTransform.get());

* * *

My "laser" is a MatrixTransform holding a Geode having a Geometry Drawable with a Texture2D of an image I generate.

I've set "setCullingActive( false)" on the MatrixTransform and the Geode (square).  I've setup a CullCallback with:
    virtual bool cull(osg::NodeVisitor*, osg::Drawable*, osg::State*) const { return false; }
And applied that the the drawable.

As this iamge shrinks into the distance, it (still) becomes invisible.

My coworker (who is knowledgeable of OpenGL, but not so much of OpenSceneGraph), suggests MIP-mapping.  I can move to that, it that's the next step.

Any other suggestions?


Philip A. Tessier
Northrop Grumman IT
Philip.Tessier at ngc.com
Cell 210-867-6775

-----Original Message-----
From: osg-users-bounces at lists.openscenegraph.org [mailto:osg-users-bounces at lists.openscenegraph.org] On Behalf Of Jean-Sébastien Guay
Sent: Friday, July 18, 2008 7:05 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] Node needs to render at least one pixel

Hello Philip,

> I've implemented Jean-Sébastien's last suggestion, "node->setCullingActive(false)" on the MatrixTransform whose child is the image, but with no noticeable change.  Does this setting affect a node's children as well?  I've checked my viewing frustrum, and zFar is set to 3.0*(the scene node's getBound()).

Well, culling tests each node's bounding sphere. In the case of a group (or subclass), the bounding sphere contains the bounding spheres of the children. If a given node is not culled, then the children's bounding spheres are tested. If the node is culled, then its children are also culled (since their bounds were included in their parent's bound).

So if your laser is a group, you would need to setCullingActive(false) on the children too. Then, I don't know when the drawables are checked for culling too (they are culled with a bounding box). You might have to set a CullCallback on the Drawables that just returns false all the time.

Then again, I'm not quite sure that's your problem. If you say you're rendering a line, then because of sampling, even if the line is not culled it might not render onto any pixels. Not quite sure how I'd fix that. Perhaps unprojecting the line's endpoints so they're in screen space and then drawing a line in screen space would work?

Hope that gives you something to go with...

Jean-Sebastien Guay    jean-sebastien.guay at cm-labs.com
                         http://whitestar02.webhop.org/ _______________________________________________
osg-users mailing list
osg-users at lists.openscenegraph.org

More information about the osg-users mailing list