OSG基本图元(上)

╄→尐↘猪︶ㄣ 提交于 2020-01-31 19:35:36

```cpp
#include <Windows.h>
#include <iostream>
#include<osgDB/ReadFile>
#include<osgGA/GUIEventAdapter>
#include<osgViewer/Viewer>
#include<osg/Geode>
#include<osg/ShapeDrawable>
#include<osgDB/ReadFile>
#include<osg/Material>
#include<osg/StateSet>



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::Box(osg::Vec3(0.0, 0.0, 0.0), 1.0, 10.0, 10.0));
	osg::ref_ptr<osg::Material> material = new osg::Material;
	osg::ref_ptr<osg::Texture2D> texture2D = new osg::Texture2D;
	//设置颜色
	shape->setColor(osg::Vec4(0.5, 0.5, 0.5, 0.1));
	//设置精度
	hints->setDetailRatio(0.5);
	//设置材质
	material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0, 1.0, 1.0, 1.0));
	material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0, 1.0, 1.0, 1.0));
	material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0, 1.0, 1.0, 1.0));
	material->setShininess(osg::Material::FRONT_AND_BACK, 60.0);
	//设置纹理

	geode->getOrCreateStateSet()->setAttributeAndModes(material.get(), osg::StateAttribute::ON);
	geode->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
	geode->addDrawable(shape.get());
	return geode;
}


int main()
{
	osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
	viewer->setSceneData(CreateBox());
	return viewer->run();


}


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!