|
在编程指南第九章中有如下一段代码:Main函数1
int main()
{
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer();
//创建各种文字效果
osg::ref_ptr<osg::Camera> camera = createAllKindText();
//添加到根节点
osg::ref_ptr<osg::Group> root = new osg::Group() ;
root->addChild(createAllKindText());
//优化场景数据
osgUtil::Optimizer optimizer ;
optimizer.optimize(root.get()) ;
viewer->setSceneData(root.get());
viewer->realize();
viewer->run();
return 0 ;
}
这个camera应该是新建的从相机?其中creatAllKindText返回是一个从相机
但是viewer->getCamera()这个主相机应该默认就存在吧?
osg::ref_ptr<osg::Camera> createAllKindText()
{
osg::ref_ptr<osg::Camera> camera = new osg::Camera() ;
//设置投影矩阵
camera->setProjectionMatrix(osg::Matrix:rtho2D(0,1280,0,800));
//设置视图矩阵
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setViewMatrix(osg::Matrix::identity());
//清除深度缓存
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
//设置渲染顺寻,在主摄像机之前渲染
camera->setRenderOrder(osg::Camera:OST_RENDER);
//设置为不接收事件,始终不得到焦点
camera->setAllowEventFocus(false);
osg::ref_ptr<osgText::Font> font = osgText::readFontFile("fonts/arial.ttf");
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
osg::ref_ptr<osg::StateSet> stateset = geode->getOrCreateStateSet();
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
//-----------------------------------------------//-----------------------------------------------
//设置文字输出的格式
//设置格式为LEFT_TO_RIGHT,从左到右
{
osg::ref_ptr<osgText::Text> text = new osgText::Text;
text->setFont(font.get());
text->setColor(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
text->setCharacterSize(20.0f);
text->setPosition(osg::Vec3(50.0f,750.0f,0.0f));
text->setLayout(osgText::Text:EFT_TO_RIGHT);
text->setText("text->setLayout(osgText::Text::LEFT_TO_RIGHT);");
geode->addDrawable(text.get());
}
//设置格式为RIGHT_TO_LEFT,从右到左
{
osg::ref_ptr<osgText::Text> text = new osgText::Text;
text->setFont(font.get());
text->setColor(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
text->setCharacterSize(30.0f);
text->setPosition(osg::Vec3(1200.0f,750.0f,0.0f));
text->setLayout(osgText::Text::RIGHT_TO_LEFT);
text->setAlignment(osgText::Text::RIGHT_BASE_LINE);
text->setText("text->setLayout(osgText::Text::RIGHT_TO_LEFT);");
geode->addDrawable(text.get());
}
//设置格式为VERTICAL,垂直
{
osg::ref_ptr<osgText::Text> text = new osgText::Text;
text->setFont(font.get());
text->setColor(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
text->setCharacterSize(20.0f);
text->setPosition(osg::Vec3(50.0f,750.0f,0.0f));
text->setLayout(osgText::Text::VERTICAL);
text->setText("text->setLayout(osgText::Text::VERTICAL);");
geode->addDrawable(text.get());
}
//-----------------------------------------------//-----------------------------------------------
//设置阴影
{
osg::ref_ptr<osgText::Text> text = new osgText::Text;
text->setFont(font.get());
text->setColor(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
text->setCharacterSize(40.0f);
text->setPosition(osg::Vec3(100.0f,650.0f,0.0f));
//设置阴影为DROP_SHADOW_BOTTOM_RIGHT
text->setBackdropType(osgText::Text:ROP_SHADOW_BOTTOM_RIGHT);
text->setBackdropColor(osg::Vec4(0.0f,1.0f,0.0f,1.0f));
text->setBackdropOffset(0.1f,-0.1f);
text->setText("text->setBackdropType(osgText::Text::DROP_SHADOW_BOTTOM_RIGHT);");
geode->addDrawable(text.get());
}
//-----------------------------------------------//-----------------------------------------------
//设置边框
{
osg::ref_ptr<osgText::Text> text = new osgText::Text;
text->setFont(font.get());
text->setColor(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
text->setCharacterSize(30.0f);
text->setPosition(osg::Vec3(100.0f,450.0f,0.0f));
//设置边框对齐绘制
text->setDrawMode(osgText::Text::TEXT | osgText::Text::BOUNDINGBOX | osgText::Text::ALIGNMENT);
text->setText("text->setDrawMode(osgText::Text::TEXT | osgText::Text::BOUNDINGBOX | osgText::Text::ALIGNMENT);");
geode->addDrawable(text.get());
}
//-----------------------------------------------//-----------------------------------------------
//设置颜色倾斜模式
{
osg::ref_ptr<osgText::Text> text = new osgText::Text;
text->setFont(font.get());
text->setColor(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
text->setCharacterSize(40.0f);
text->setPosition(osg::Vec3(100.0f,250.0f,0.0f));
//设置颜色倾斜模式为PER_CHARACTER
text->setColorGradientMode(osgText::Text::PER_CHARACTER);
//设置倾斜四个角落的颜色
text->setColorGradientCorners(osg::Vec4(1.0f,0.0f,0.0f,1.0f),osg::Vec4(0.0f,1.0f,0.0f,1.0f),
osg::Vec4(0.0f,0.0f,1.0f,1.0f),osg::Vec4(1.0f,1.0f,1.0f,1.0f));
text->setText("text->setColorGradientMode(osgText::Text::SOLID);");
geode->addDrawable(text.get());
}
camera->addChild(geode.get());
return camera.get() ;
}
为什么说是在主摄相机之前渲染? 从摄像机和主摄像机之间关系怎样理解?
我现在只明白应该是在camera相机内部最后一个渲染,但是我不理解FlySky为什么说是在 主摄像机之前渲染。我想这里有一个我不明白的知识点吧,望高人指点迷津。
Main函数2
int main()
{
//根节点
osg::Group* root = new osg::Group();
root = createTrans();
osgViewer::Viewer viewer;
//创建节点到场景中
viewer.setSceneData(root);
viewer.realize();
return viewer.run();
}
另外像这样相机节点是加在哪里,这个流程原理不明白,上面的Main函数中camera节点下挂实体节点,这个main函数的相机节点跟root节点是怎么关联的?
|
|