Time for action—achieving the translucent effect

We are going to implement a common translucent effect that treats a model as glass. Any other scene objects can be displayed through the glass object. This can be done with the OpenGL blending mechanism, but it is important to calculate the correct rendering order of scene objects in this case.

  1. Include the necessary headers:
    #include <osg/BlendFunc>
    #include <osg/Texture2D>
    #include <osg/Geometry>
    #include <osgDB/ReadFile>
    #include <osgViewer/Viewer>
    
  2. We will continue using the quad geometry with a predefined texture coordinate array. It should be treated as a translucent object and the blending attribute and modes should be applied later:
    osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array; ...

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.