當前位置:首頁 » 操作系統 » 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 16:11:41 瀏覽:74
走心機編程教學 發布:2025-07-01 15:34:30 瀏覽:222
安卓系統哪個bug最少 發布:2025-07-01 15:34:16 瀏覽:783
不是安卓怎麼讓時間顯示在屏幕上 發布:2025-07-01 15:20:54 瀏覽:516
黃岩數控編程培訓 發布:2025-07-01 15:12:30 瀏覽:981
迷宮尋路演算法 發布:2025-07-01 15:12:29 瀏覽:546
微信視頻緩存目錄 發布:2025-07-01 14:58:59 瀏覽:396
vmwarelinux教程 發布:2025-07-01 14:50:33 瀏覽:499
名詞解釋預演算法 發布:2025-07-01 14:34:36 瀏覽:920
iis文件拒絕訪問 發布:2025-07-01 14:34:20 瀏覽:571