[osg-users] Slave camera lighting with disabled main camera

Ravi Mathur ravidavi at utexas.edu
Mon Jan 8 17:07:16 PST 2018

Hi all,

Sorry to bring up yet another question about osg::View::setLightingMode(NO_LIGHT), but I'm having trouble understanding some lighting behavior.

Suppose I have a simple scene with no explicitly-specified StateSets ... e.g. I'm not setting lights or enabling GL_LIGHTING or anything like that. If I do viewer.setLightingMode(NO_LIGHT), then as expected the viewer doesn't set up any light and doesn't enable GL_LIGHTING. If I add a slave camera, then that slave camera also has no lighting, also as expected.

Now suppose I disable the main camera using viewer.getCamera()->setGraphicsContext(NULL). Suddenly, the slave camera goes back to the default headlight! I've searched around and looked through the code for Renderer and SceneView, but am not able to make sense of this. Can anyone please explain it?

BTW I'm on the OpenSceneGraph-3.5.6 Git tag.


Here's the minimal example code to duplicate this behavior.

using namespace osg;
int main()
  // Standard OSG sphere
  ShapeDrawable* sphereSD = new ShapeDrawable(new Sphere());
  Geode *sphereGeode = new Geode();
  // Viewer with no light
  osgViewer::Viewer viewer;
  viewer.setUpViewInWindow(30, 30, 640, 480);
  // Slave camera
  Camera* slaveCam = new Camera();

  // Disable main camera
  // This causes slaveCam to have default HEADLIGHT: why??
  return viewer.run();

Read this topic online here:

More information about the osg-users mailing list