Osg-Osg利用Texture2D给球面贴图(Qt5.14.2+osgE3.6.5+win10)-No28-Texture2D

相关资料:

https://blog.csdn.net/forcsdn_tang/article/details/122273695

 

实例代码:

.pro

 1 QT       += core gui widgets
 2 QT       += opengl
 3 TARGET = TestOsgQt
 4 TEMPLATE = app
 5 DEFINES += QT_DEPRECATED_WARNINGS
 6 CONFIG += c++11
 7 
 8 SOURCES += \
 9         main.cpp
10 
11 HEADERS +=
12 
13 OsgDir = D:\\Gitee\\osg365R
14 CONFIG(release, debug|release) {
15         LIBS += -L$${OsgDir}/lib/ -losgDB -losgViewer -lOpenThreads -losgAnimation -losg \
16                                   -losgEarth -losgEarthAnnotation -losgEarthFeatures -losgEarthSymbology -losgEarthUtil \
17                                   -losgQOpenGL -losgUtil -losgText -losgTerrain -losgSim \
18                                   -losgShadow -losgParticle -losgManipulator -losgGA -losgFX \
19                                   -losgWidget
20 } else {
21         LIBS += -L$${OsgDir}/debug/lib/ -losgDBd -losgViewerd -lOpenThreadsd -losgAnimationd -losgd \
22                                   -losgEarthd -losgEarthAnnotationd -losgEarthFeaturesd -losgEarthSymbologyd -losgEarthUtild \
23                                   -losgQOpenGLd -losgUtild -losgTextd -losgTerraind -losgSimd \
24                                   -losgShadowd -losgParticled -losgManipulatord -losgGAd -losgFXd \
25 }
26 
27 LIBS += -lOpenGL32
28 LIBS += -lGlU32
29 
30 INCLUDEPATH += $${OsgDir}/include
31 DEPENDPATH += $${OsgDir}/include
View Code

main.cpp 

 1 #include <osgViewer/Viewer>
 2 
 3 #include <osg/Node>
 4 #include <osg/Geode>
 5 #include <osg/Group>
 6 #include <osg/NodeCallback>
 7 #include <osg/MatrixTransform>
 8 
 9 #include <osgDB/ReadFile>
10 #include <osgDB/WriteFile>
11 
12 #include <osgUtil/Optimizer>
13 
14 #include <osg/ShapeDrawable>
15 #include <osg/Texture2D>
16 #include <osgViewer/Viewer>
17 #include <osgDB/ReadFile>
18 
19 #include <iostream>
20 
21 int main()
22 {
23     std::cout << "Hello, osg!" << std::endl;
24 
25     osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
26     viewer->setUpViewInWindow(50,50,500,400);
27     osg::ref_ptr<osg::Geode> geode = new osg::Geode;
28     geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(), 1.0f)));
29     osg::ref_ptr<osg::Texture> texture = new osg::Texture2D(osgDB::readRefImageFile("D:/Gitee/data/purpleFlowers.png"));
30     auto stateSet = geode->getOrCreateStateSet();
31     stateSet->setTextureAttributeAndModes(0, texture);
32     viewer->setSceneData(geode);
33     return viewer->run();
34 }
View Code

 

 

posted on 2022-08-16 15:03  疯狂delphi  阅读(114)  评论(0编辑  收藏  举报

导航