Time for action - loading and applying 2D textures

The most common texture mapping technique is 2D texture mapping. This accepts a 2D image as the texture and maps it onto one or more geometry surfaces. The osg::Texture2D class is used here as a texture attribute of a specific texture mapping unit.

  1. Include the necessary headers:
    #include <osg/Texture2D>
    #include <osg/Geometry>
    #include <osgDB/ReadFile>
    #include <osgViewer/Viewer>
    
  2. We will quickly create a quad and call the setTexCoordArray() method to bind texture coordinates per vertex. The texture coordinate array only affects the texture unit 0 in this example, but it is always possible to share arrays among units:
    osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array; vertices->push_back( ...

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.