|
#include "stdafx.h"
#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osg/geode>
#include <osg/LineWidth>
osg::ref_ptr<osg::Vec3Array> m_VertexV3a;
void DrawAreaWithType(int PolygonMode,osg::Geometry* PolygonGeometry,osg::StateSet* PolygonStateset)
{
PolygonStateset->setMode(GL_BLEND,osg::StateAttribute::ON);
PolygonStateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
PolygonStateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF|osg::StateAttribute:ROTECTED);
osg::ref_ptr <osg:ineWidth> LineSize = new osg::LineWidth;
LineSize ->setWidth(2.0) ;
PolygonStateset->setAttributeAndModes(LineSize.get(),osg::StateAttribute::ON);
PolygonGeometry->setStateSet(PolygonStateset);
PolygonGeometry->setVertexArray(m_VertexV3a);
PolygonGeometry->setTexCoordArray(0,m_VertexV3a);
PolygonGeometry->addPrimitiveSet(new osg:rawArrays(PolygonMode,0,m_VertexV3a->size()));
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
osg::Vec4 color(0.2,0.2,0.2,0.8);
colors->push_back(color);
PolygonGeometry->setColorArray(colors);
PolygonGeometry->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);
osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
osg::Vec3 normal = osg::Z_AXIS;
normals->push_back(normal);
PolygonGeometry->setNormalArray(normals.get());
PolygonGeometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);
}
int _tmain(int argc, _TCHAR* argv[])
{
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
osg::ref_ptr<osg::Group> g_Root = new osg::Group;
osg::ref_ptr<osg::Node> pNode = new osg::Node;
if(!pNode)
return 0;
m_VertexV3a = new osg::Vec3Array;
m_VertexV3a->push_back(osg::Vec3(-0.1f,0.1f,-0.1f));
m_VertexV3a->push_back(osg::Vec3(0.1f,0.1f,-0.1f));
m_VertexV3a->push_back(osg::Vec3(0.1f,0.1f,0.1f));
m_VertexV3a->push_back(osg::Vec3(-0.1f,0.1f,0.1f));
osg::Geometry* PolygonGeometry = new osg::Geometry;
osg::StateSet* PolygonStateset = new osg::StateSet;
DrawAreaWithType(osg::PrimitiveSet::POLYGON,PolygonGeometry,PolygonStateset);
g_Root->addChild(pNode);
viewer->setSceneData(g_Root);
viewer->run();
return 0;
} |
|