OpenSceneGraph
一、3.6.5 下载
http://www.openscenegraph.com/index.php/download-section/stable-releases
二、vs 工程 配置
bin
include
lib
include、lib添加至工程 VC++目录下的 包含目录、库目录
bin目录可直接拷贝至 vs工程 Debug 目录下
三、HelloWorld
1.引入库
代码如下(WIN32控制台程序 或 C/C++预处理器定义添加WIN32):
#include <string>
#include <osgViewer/Viewer>
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osg/Geode>
#include <osg/ShapeDrawable>
// bin 目录或可添加至 环境变量
int main()
{
/*std::string cowData = R"(E:\OsgProjects\OpenSceneGraph-3.6.5-VC2022-64-Debug\OpenSceneGraph-Data-3.4.0\OpenSceneGraph-Data\cow.osg)";
osgViewer::Viewer viewer;
viewer.setSceneData(osgDB::readNodeFile(cowData));
return viewer.run();*/
std::string world_png = R"(E:\OsgProjects\OpenSceneGraph-3.6.5-VC2022-64-Debug\png\world.png)";
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
viewer->setUpViewInWindow(50, 50, 800, 600);
// 叶节点
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
// Texture
osg::ref_ptr<osg::Texture> texture = new osg::Texture2D(osgDB::readRefImageFile(world_png));
geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(), 1.0f)));
auto stateSet = geode->getOrCreateStateSet();
stateSet->setTextureAttributeAndModes(0, texture);
viewer->setSceneData(geode);
return viewer->run();
}
2.运行
参考:https://blog.csdn.net/forcsdn_tang/article/details/122273695