[vtkusers] Changing RenderWindow background color

Cesar Oleskovicz cesar.oleskovicz at onix.com.br
Wed Mar 6 10:48:28 EST 2002


Hi all,

    I did a little class that open an stl file, the construction of this classe set all parameters to see a blue background and gouraud shaded object.
    I instantiate my class on WM_CREATE funcion of visual c++ wizard.

    Until now all works fine, but when I try change background color through a method that I implemented, I always recieve a error message saying the memory can't be read, acess violation.

    What is wrong ?
    Can't I acess a RenderWindow object method after it has being created ?

    Look a fragment of my code:

method to change background color:

    void CVTKStlViewer::BackgroundColor(COLORREF newColor)
{
 
 ren->SetBackground(GetRValue(newColor),GetGValue(newColor),GetBValue(newColor)); // this line is the problem
 iren->Render();

}
    
constructor:
CVTKStlViewer::CVTKStlViewer(HWND childview)
{
 BkgColor = RGB(0,0,1);
 ObjColor = RGB(1,0.5,0);
 


 // create a rendering window and renderer
  vtkRenderer *ren = vtkRenderer::New();
  vtkRenderWindow *renWindow = vtkRenderWindow::New();
    renWindow->AddRenderer(ren);
 renWindow->SetParentId(childview);
 renWindow->SetSize( 800, 600 );

 iren = vtkRenderWindowInteractor::New();
 vtkInteractorStyleTrackballCamera *TrackballCameraStyle = vtkInteractorStyleTrackballCamera::New();

  iren->SetInteractorStyle (TrackballCameraStyle);
  iren->SetRenderWindow(renWindow);

 sr = vtkSTLReader::New();
  sr->SetFileName ("c:/vtk-src-windows/vtkData/cow.stl");

 vtkPolyDataNormals *pNormals = vtkPolyDataNormals::New();
  pNormals->SetFeatureAngle (80);
  pNormals->SetInput(sr->GetOutput());

 stlMapper = vtkPolyDataMapper::New();
  stlMapper->SetInput(pNormals->GetOutput());

 stlActor = vtkLODActor::New();
  stlActor->SetMapper(stlMapper);
  stlActor->GetProperty()->SetColor(GetRValue(ObjColor),GetGValue(ObjColor),GetBValue(ObjColor));


  stlActor->GetProperty()->SetInterpolationToGouraud();

 ren->AddActor(stlActor);
 ren->SetBackground(GetRValue(BkgColor),GetGValue(BkgColor),GetBValue(BkgColor));

  // draw the resulting scene
 renWindow->Render();

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20020306/ea5db422/attachment.htm>


More information about the vtkusers mailing list