Time for action - drawing an octahedron

An octahedron is a polyhedron having eight triangle faces. It is really a nice example to show why primitive indexing is important. We will first sketch the octahedron structure, as shown in the following image:

Time for action - drawing an octahedron

The octahedron has six vertices, each shared by four triangles. We would have to create a vertex array with 24 elements to render all eight faces when using osg::DrawArrays. However, with the help of an index array and the osg::DrawElementsUInt class, we can allocate a vertex array with only six elements and thus improve the efficiency of drawing the geometry.

  1. Include the necessary headers:
    #include ...

Get OpenSceneGraph 3.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.