[vtkusers] Light : Is there any specific order to create?

S.K.Bose bose at magnum.barc.ernet.in
Mon Sep 6 04:05:09 EDT 2004


Hello !

Is there any specific order to create Light. For example with the
following code the cone is not mapped properly within the Viewport.

#include "vtkConeSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkCamera.h"
#include "vtkActor.h"
#include "vtkRenderer.h"

void main( int argc, char *argv[] )
{
  vtkRenderer *ren1= vtkRenderer::New();
  ren1->SetBackground( 0.1, 0.2, 0.4 );
  ren1->CreateLight();                // Create Light here
  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer( ren1 );
  renWin->SetSize( 300, 300 );
  vtkConeSource *cone = vtkConeSource::New();
  vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
  coneMapper->SetInput( cone->GetOutput() );
  vtkActor *coneActor = vtkActor::New();
  coneActor->SetMapper( coneMapper );
  ren1->AddActor( coneActor );
  //ren1->CreateLight();              // Don't create light here
  int i;
  for (i = 0; i < 360; ++i)
    {
    renWin->Render();
    ren1->GetActiveCamera()->Azimuth( 1 );
    }
  ren1->Delete();
  renWin->Delete();
  cone->Delete();
  coneMapper->Delete();
  coneActor->Delete();
}

But with the following code, the cone is mapped properly as expected.

void main( int argc, char *argv[] )
{
  vtkRenderer *ren1= vtkRenderer::New();
  ren1->SetBackground( 0.1, 0.2, 0.4 );
  //ren1->CreateLight();               // Don't Create Light here
  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer( ren1 );
  renWin->SetSize( 300, 300 );
  vtkConeSource *cone = vtkConeSource::New();
  vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
  coneMapper->SetInput( cone->GetOutput() );
  vtkActor *coneActor = vtkActor::New();
  coneActor->SetMapper( coneMapper );
  ren1->AddActor( coneActor );
  ren1->CreateLight();                     // create light here
  int i;
  for (i = 0; i < 360; ++i)
    {
    renWin->Render();
    ren1->GetActiveCamera()->Azimuth( 1 );
    }
  ren1->Delete();
  renWin->Delete();
  cone->Delete();
  coneMapper->Delete();
  coneActor->Delete();
}

I have no idea why this kind of behavior is happening. IMO, it should not
be a matter where I am going to create Light object, after all OpenGL
lighting model will be called in "Render" method of vtkRenderer or am I
missing something?

I have tested this with current CVS.

Thanks in advance,

S. K. Bose





More information about the vtkusers mailing list