首页 > 其他 > 详细

绘制四边形

时间:2021-08-25 18:36:23      阅读:10      评论:0      收藏:0      [点我收藏+]

绘制四边形

  1. 点显示 osg::PolygonMode::POINT
  2. 线显示 osg::PolygonMode::LINE
  3. 面显示 osg::PolygonMode::FILL
#include <windows.h>
#include <osg\node>
#include <osg\group>
#include <osg\geometry>
#include <osg\matrixtransform>
#include <osg\Point>
#include <osg\LineWidth>
#include <osg\LineStipple>
#include <osgViewer\Viewer>

int main()
{
	osgViewer::Viewer viewer;

	osg::ref_ptr<osg::group> group = new osg::Group();
	viewer.setSceneData(group);

	osg::ref_ptr<osg::geode> geode = new osg::Geode();
	geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
	geode->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
	geode->getOrCreateStateSet()->setAttributeAndModes(new osg::Point(5.0f));
	geode->getOrCreateStateSet()->setAttributeAndModes(new osg::LineWidth(2.0f));
	geode->getOrCreateStateSet()->setAttributeAndModes(new osg::LineStipple(1, 0x0F0F));
	geode->getOrCreateStateSet()->setAttributeAndModes(new osg::PolygonMode(osg::PolygonMode::FRONT, osg::PolygonMode::FILL));
	osg::ref_ptr<osg::geometry> geometry = new osg::Geometry();

	//顶点
	osg::ref_ptr<osg::vec3array> vertex = new osg::Vec3Array();
	vertex->push_back(osg::Vec3(-1.0, -1.0, 0.5));
	vertex->push_back(osg::Vec3(1.0, -1.0, 0.5));
	vertex->push_back(osg::Vec3(1.0, 1.0, 0.5));
	vertex->push_back(osg::Vec3(-1.0, 1.0, 0.5));
	geometry->setVertexArray(vertex);

	//颜色
	osg::ref_ptr<osg::vec4array> colors = new osg::Vec4Array();
	colors->push_back(osg::Vec4(1.0, 1.0, 1.0, 0.5));
	geometry->setColorArray(colors, osg::Array::BIND_OVERALL);

	//图元装配
	geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::Mode::QUADS, 0, vertex->size()));

	geode->addDrawable(geometry);
	group->addChild(geode);

	viewer.setUpViewInWindow(100, 100, 500, 400);
	return viewer.run();
}

技术分享图片
技术分享图片
技术分享图片

绘制四边形

原文:https://www.cnblogs.com/shiguoliang/p/15185621.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!