Time for action—drawing a colored quad

Let's work on a common shape in order to see the steps to complete a renderable geometry model. We will create a quadrangle with only four vertices as the four corners, and use GL_QUADS mode to draw these vertices. The GL_QUADS mode tells OpenGL to combine the first four coordinates in the vertex array as one quad, the second four as the second quad, and so on.

  1. Include the necessary headers:
    #include <osg/Geometry>
    #include <osg/Geode>
    #include <osgViewer/Viewer>
    
  2. Create the vertex array and push the four corner points to the back of the array by using std::vector like operations:
    osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array; vertices->push_back( osg::Vec3(0.0f, 0.0f, 0.0f) ); vertices->push_back( ...

Get OpenSceneGraph 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.