|
发现osgText在使用了shadow map之后字体颜色一直都是黑色的。有没有人知道这是为什么?如何才能改变text字体颜色呢?另外除了osgText现在有什么常用的字体显示的方法?
写了一个简单的程序验证了一下:
#include <osgShadow/ShadowedScene>
#include <osgShadow/ShadowMap>
#include <osg/Geode>
#include <osg/PolygonMode>
#include <osg/PositionAttitudeTransform>
#include <osgText/Font>
#include <osgText/Text>
#include <osg/ShapeDrawable>
#include <osg/Material>
#include <osgGA/TrackballManipulator>
#include <osgViewer/Viewer>
#include <osgViewer/View>
int main()
{
osgViewer::Viewer viewer;
osg::ref_ptr<osgShadow::ShadowedScene> shadowedScene = new osgShadow::ShadowedScene;
shadowedScene->setReceivesShadowTraversalMask(1);
shadowedScene->setCastsShadowTraversalMask(2);
osg::ref_ptr<osgShadow::ShadowMap> sm = new osgShadow::ShadowMap;
shadowedScene->setShadowTechnique(sm.get());
osgText::Font* font = osgText::readFontFile("C:/WINDOWS/Fonts/arial.ttf");
float charSize = 10.0f;
osg::Vec3 numPos,digitPos;
digitPos = osg::Vec3(-20,0,93);
osg::ref_ptr<osgText::Text> label = new osgText::Text;
osg::ref_ptr<osg::Geode> labelGeode = new osg::Geode;
labelGeode->addDrawable(label.get());
label->setCharacterSize(charSize);
label->setFont(font);
label->setColor(osg::Vec4(1.0,1.0,1.0,1.0));
char test[2];
test[0] = '0';
test[1] = '\0';
label->setText(test);
label->setDrawMode(osgText::Text::TEXT | osgText::Text::BOUNDINGBOX);
label->setPosition( digitPos );
label->setRotation(osg:uat(osg:egreesToRadians(30.00),osg::Vec3(1,0,0),osg::DegreesToRadians(30.00),osg::Vec3(0,1,0),osg::DegreesToRadians(-90.00),osg::Vec3(0,0,1)));
shadowedScene->addChild(labelGeode.get());
viewer.setSceneData(shadowedScene.get());
viewer.setCameraManipulator(new osgGA::TrackballManipulator());
viewer.realize();
while (!viewer.done())
{
viewer.frame();
}
}
|
|