|
执行这段代码之后屏幕上什么也没得 使用text文本测试 camera的设置时没问题的 请各位大大看看!!附上代码
#include <osg/Node>
#include <osg/Geometry>
#include <osg/Notify>
#include <osg/MatrixTransform>
#include <osg/Texture2D>
#include <osg/Billboard>
#include <osg/LineWidth>
#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgDB/Registry>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osg/Camera>
#include <osg/Material>
#include <osg/Depth>
#include <osgText/Text>
#include "South.h"
typedef std::vector< osg::ref_ptr<osg::Image> > ImageList;
osg:rawable* createSquare(const osg::Vec3& corner,const osg::Vec3& width,const osg::Vec3& height, osg::Image* image=NULL)
{
osg::Geometry* geom = new osg::Geometry;
osg::Vec3Array* coords = new osg::Vec3Array(4);
(*coords)[0] = corner;
(*coords)[1] = corner+width;
(*coords)[2] = corner+width+height;
(*coords)[3] = corner+height;
geom->setVertexArray(coords);
osg::Vec3Array* norms = new osg::Vec3Array(1);
(*norms)[0] = width^height;
(*norms)[0].normalize();
geom->setNormalArray(norms);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
osg::Vec2Array* tcoords = new osg::Vec2Array(4);
(*tcoords)[0].set(0.0f,0.0f);
(*tcoords)[1].set(1.0f,0.0f);
(*tcoords)[2].set(1.0f,1.0f);
(*tcoords)[3].set(0.0f,1.0f);
geom->setTexCoordArray(0,tcoords);
geom->addPrimitiveSet(new osg::DrawArrays(osg:rimitiveSet:UADS,0,4));
if (image)
{
osg::StateSet* stateset = new osg::StateSet;
osg::Texture2D* texture = new osg::Texture2D;
texture->setImage(image);
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
geom->setStateSet(stateset);
}
return geom;
}
osg::Camera* createModel()
{
osg::Camera* camera = new osg::Camera;
camera->setProjectionMatrix(osg::Matrix:rtho2D(0,1024,0,768));
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setViewMatrix(osg::Matrix::identity());
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
camera->setRenderOrder(osg::Camera::POST_RENDER);//设置渲染顺序放在最后渲染那
camera->setAllowEventFocus(false);
osg::Group* root = new osg::Group();
osg::Billboard* center = new osg::Billboard();
center->setMode(osg::Billboard::POINT_ROT_WORLD);
center->addDrawable(
createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readImageFile("Images/clockface.JPG")),
osg::Vec3(150.0f,500.0f,0.0f));
osg::Billboard* center1 = new osg::Billboard();
center1->setMode(osg::Billboard::POINT_ROT_EYE);
center1->addDrawable(
createSquare(osg::Vec3(0.0f,-0.00001f,0.0f),osg::Vec3(0.1f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,0.1f),osgDB::readImageFile("Images/north.png")),
osg::Vec3(150.0f,500.0f,0.0f));
root->addChild(center);
root->addChild(center1);
camera->addChild(root);
return camera;
}
int main(int, char**)
{
osgViewer::Viewer viewer;
osg::Vec3d position,center,up;
osg::Group* root = new osg::Group();
root->addChild(createModel());
root->addChild(osgDB::readNodeFile("cow.osg"));
viewer.setSceneData(root);
viewer.realize();
return viewer.run();
} |
|