Time for action—creating light sources in the scene
By default, OSG automatically turns on the first light (GL_LIGHT0
) and gives the scene a soft, directional light. However, this time we will create multiple lights by ourselves, and move them with transformation parent nodes. Be aware: only positional lights can be translated. A directional light has no origin and cannot be placed anywhere.
OpenGL and OSG both use the fourth component of the position parameter to decide if a light is a point light. That is to say, if the fourth component is 0, the light is treated as a directional source; otherwise it is positional.
- Include the necessary headers:
#include <osg/MatrixTransform> #include <osg/LightSource> #include <osgDB/ReadFile> #include <osgViewer/Viewer> ...
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.