Osg 真 HelloWorld

Osg 真 HelloWorld,第1张

OpenSceneGraph
  • 一、3.6.5 下载
  • 二、vs 工程 配置
  • 三、HelloWorld
    • 1.引入库
    • 2.运行


一、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 

#include 
#include 
#include 
#include 
#include 

// 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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/3002782.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-09-27
下一篇 2022-09-27

发表评论

登录后才能评论

评论列表(0条)

保存