#include #include #include #include #include int main(int argc, char** argv) { // Create the geometry which will define the triangle osg::ref_ptr myTriangleGeometry = new osg::Geometry; // Define the triangle's 3 vertices osg::ref_ptr vertices = new osg::Vec3Array; vertices->push_back(osg::Vec3(0, 0, 0)); vertices->push_back(osg::Vec3(100, 0, 0)); vertices->push_back(osg::Vec3(0, 0, 100)); myTriangleGeometry->setVertexArray(vertices); // You can give each vertex its own color, but let's just make it green for now osg::ref_ptr colors = new osg::Vec4Array; colors->push_back(osg::Vec4(0, 1.0, 0, 1.0)); // RGBA for green myTriangleGeometry->setColorArray(colors); myTriangleGeometry->setColorBinding(osg::Geometry::BIND_OVERALL); // Turn off lighting myTriangleGeometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); // Turn on blending myTriangleGeometry->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON); // Define the geometry type as 'triangles' myTriangleGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, vertices->size())); // Finally, let's add our triangle to a geode osg::ref_ptr myGeode = new osg::Geode; myGeode->addDrawable(myTriangleGeometry); // And now we can create a viewer to look at our geode osgViewer::Viewer viewer; viewer.setSceneData(myGeode); return viewer.run(); }