[osg-users] How to disable Antialiasing of an osg::Text

Lv Qing donlvqing at msn.com
Tue Mar 14 10:07:22 PDT 2017


Hi,

Thx Robert!
 
   I use one of osgEarth fuction to rendering my text.



Code:


osg::ref_ptr<osgText::Text> PowerPlaceNode::createPlaceNodeTextDrawable(const std::string& text,
		const TextSymbol* symbol, const osg::Vec3& positionOffset)
{
	osg::ref_ptr < osgText::Text > t = new osgText::Text();
	osgText::String::Encoding text_encoding = osgText::String::ENCODING_UNDEFINED;
	if (symbol && symbol->encoding().isSet())
	{
		switch (symbol->encoding().value())
		{
		case TextSymbol::ENCODING_ASCII:
			text_encoding = osgText::String::ENCODING_ASCII;
			break;
		case TextSymbol::ENCODING_UTF8:
			text_encoding = osgText::String::ENCODING_UTF8;
			break;
		case TextSymbol::ENCODING_UTF16:
			text_encoding = osgText::String::ENCODING_UTF16;
			break;
		case TextSymbol::ENCODING_UTF32:
			text_encoding = osgText::String::ENCODING_UTF32;
			break;
		default:
			text_encoding = osgText::String::ENCODING_UTF8;
			break;   //editby lvqing 20140509
		}
	}

	t->setText(text, osgText::String::ENCODING_UTF8);


	if (symbol && symbol->pixelOffset().isSet())
	{
		t->setPosition(
				osg::Vec3(positionOffset.x() + symbol->pixelOffset()->x(),
						positionOffset.y() + symbol->pixelOffset()->y(), positionOffset.z()));
	}
	else
	{
		t->setPosition(positionOffset);
	}

	osgText::Font* font = 0L;
	if (symbol && symbol->font().isSet())
	{
		font = osgText::readFontFile(*symbol->font()); // read font*/
	}

	t->setFontResolution(256,256);

	t->setAutoRotateToScreen(false);
	t->setCharacterSizeMode(osgText::Text::OBJECT_COORDS);

	if (symbol != NULL)
	{
		if (symbol->size() != NULL)
		{
			t->setCharacterSize( symbol && symbol->size().isSet() ? *symbol->size() : 20.0f );
		}
		else
		{
			t->setCharacterSize( 20.0f );
		}
	}

	if (!font)
		font = Registry::instance()->getDefaultFont();
	if (font)
	{
		t->setFont(font);
	}

	t->setColor(symbol && symbol->fill().isSet() ? symbol->fill()->color() : Color::White);

	if (symbol)
	{
		// they're the same enum.
		osgText::Text::AlignmentType at = (osgText::Text::AlignmentType) symbol->alignment().value();
		t->setAlignment(at);
	}

	if (symbol && symbol->halo().isSet())
	{
		t->setBackdropColor(symbol->halo()->color());
		t->setBackdropType(osgText::Text::OUTLINE);

		if (symbol->haloOffset() != NULL)
		{
			if (symbol->haloOffset().isSet())
			{
				t->setBackdropOffset(*symbol->haloOffset(), *symbol->haloOffset());
			}
		}
	}
	else if (!symbol)
	{
		// if no symbol at all is provided, default to using a black halo.
		t->setBackdropColor(osg::Vec4(.3, .3, .3, 1));
		t->setBackdropType(osgText::Text::OUTLINE);
	}

	// this disables the default rendering bin set by osgText::Font. Necessary if we're
	// going to do decluttering.
	// TODO: verify that it's still OK to share the font stateset (think so) or does it
	// need to be marked DYNAMIC
	if (t->getStateSet())
		t->getStateSet()->setRenderBinToInherit();
	//osg::StateSet* stateSet = new osg::StateSet();
	//t->setStateSet( stateSet );


//#if 0 // OBE: the decluttering bin is now set higher up (in OrthoNode)

	osg::StateSet* stateSet = t->getOrCreateStateSet();

	if ( symbol && symbol->declutter().isSet() )
	{
		Decluttering::setEnabled( stateSet, *symbol->declutter() );
	}
	else
	{
	//	stateSet->setRenderBinToInherit();
		stateSet->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
	}

	t->setStateSet( stateSet );




#if 0 // OBE: shadergenerator now takes care of all this
	// add the static "isText=true" uniform; this is a hint for the annotation shaders
	// if they get installed.
	static osg::ref_ptr<osg::Uniform> s_isTextUniform = new osg::Uniform(osg::Uniform::BOOL, UNIFORM_IS_TEXT());
	s_isTextUniform->set( true );
	stateSet->addUniform( s_isTextUniform.get() );
#endif

	return t;
}







... 

Thank you!

Cheers,
Lv

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=70488#70488








More information about the osg-users mailing list