当前位置:首页 » 操作系统 » GGA源码

GGA源码

发布时间: 2024-12-20 18:15:08

‘壹’ initqtwindowingsystem;中不能使用osgtext吗

注意:

1.编译osg源码时,勾选osgQT 相关模块,这是对QT的支持

2.在QtPro文件中添加对应的库和目录

例如:


win32:INCLUDEPATH += C:/OpenSceneGraph/include
win32:DEPENDPATH += C:/OpenSceneGraph/include
unix:!macx:INCLUDEPATH += .


win32:CONFIG(release, debug|release): LIBS +=
-LC:/OpenSceneGraph/lib/ -lOpenThreads
-LC:/OpenSceneGraph/lib/ -losg
-LC:/OpenSceneGraph/lib/ -losgAnimation
-LC:/OpenSceneGraph/lib/ -losgDB
-LC:/OpenSceneGraph/lib/ -losgFX
-LC:/OpenSceneGraph/lib/ -losgGA
-LC:/OpenSceneGraph/lib/ -losgManipulator
-LC:/OpenSceneGraph/lib/ -losgParticle
-LC:/OpenSceneGraph/lib/ -losgPresentation
-LC:/OpenSceneGraph/lib/ -losgQt


3. 编写CPP文件。


#include <QApplication>

#include <osgViewer/Viewer>
#include <osgGA/TrackballManipulator>
#include <osgQt/GraphicsWindowQt>

#include <osg/ShapeDrawable>
#include <osg/MatrixTransform>
#include <osgManipulator/TabBoxDragger>
#include <osgGA/StateSetManipulator>
#include <osgViewer/ViewerEventHandlers>
#include <osgDB/ReadFile>
#include <osg/Material>
#include <osg/Texture2D>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/ShapeDrawable>
osg::ref_ptr<osg::Geode> CreateBox() {
osg::ref_ptr<osg::Geode> geode= new osg::Geode;
osg::ref_ptr<osg::TessellationHints> hints= new osg::TessellationHints;
osg::ref_ptr<osg::ShapeDrawable> shape= new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(5.0,5.0,5.0),10.0));
osg::ref_ptr<osg::Material> material= new osg::Material;
osg::ref_ptr<osg::Texture2D> texture= new osg::Texture2D;
osg::ref_ptr<osg::Image> image= new osg::Image;

hints->setDetailRatio(0.5);
//设置颜色
shape->setColor(osg::Vec4(0.1,0.5,0.5,0.5));
//设置材质
material->setAmbient(osg::Material::FRONT_AND_BACK,osg::Vec4(0.5,0.5,0.5,0.5));
material->setDiffuse(osg::Material::FRONT_AND_BACK,osg::Vec4(0.5,0.5,0.5,0.5));
material->setSpecular(osg::Material::FRONT_AND_BACK,osg::Vec4(0.5,0.5,0.5,0.5));
material->setShininess(osg::Material::FRONT_AND_BACK,0.6);
shape->getOrCreateStateSet()->setAttributeAndModes(material.get(),osg::StateAttribute::ON);

//设置纹理
image= osgDB::readImageFile("Images/land_shallow_topo_2048.jpg");
if(image->valid())
texture->setImage(image);
shape->getOrCreateStateSet()->setTextureAttributeAndModes(0,texture.get(),osg::StateAttribute::ON);

geode->addDrawable(shape);
return geode;
}


int main( int argc, char** argv )
{
QApplication app(argc, argv);
osgQt::initQtWindowingSystem();

osg::Group* sceneroot = new osg::Group;

sceneroot->addChild(CreateBox());
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
viewer->addEventHandler(new osgViewer::StatsHandler);


viewer->setSceneData( sceneroot );
viewer->setCameraManipulator( new osgGA::TrackballManipulator );
osgQt::setViewer( viewer.get() );

osgQt::GLWidget* glw = new osgQt::GLWidget;
osgQt::GraphicsWindowQt* graphicswin = new osgQt::GraphicsWindowQt(glw);

viewer->getCamera()->setViewport( new osg::Viewport(0, 0, glw->width(), glw->height() ) );
viewer->getCamera()->setGraphicsContext( graphicswin );

glw->show();

return app.exec();
}

4.效果图如下:

热点内容
名词解释预算法 发布:2025-07-01 14:34:36 浏览:915
iis文件拒绝访问 发布:2025-07-01 14:34:20 浏览:567
苹果和安卓相比哪个游戏多 发布:2025-07-01 14:24:16 浏览:759
锐界七座买哪个配置好 发布:2025-07-01 14:14:59 浏览:980
svn下载linux 发布:2025-07-01 14:10:38 浏览:732
苹果手机打游戏和安卓哪个流畅 发布:2025-07-01 13:58:41 浏览:840
中原证券服务器怎么样 发布:2025-07-01 13:57:23 浏览:998
在简便算法 发布:2025-07-01 13:32:06 浏览:766
c语言表达式绝对值 发布:2025-07-01 13:25:45 浏览:491
获取网站访问量 发布:2025-07-01 13:20:28 浏览:296