Hi,
I want to display an actor and a widget with some transparency.
It seems VTK8 was in alpha blending but VTK9 uses additive blending. Shading seems broken too.
How to do to have same rendering as in VTK 8?
#include <vtkActor.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSmartPointer.h>
#include <vtkSphereRepresentation.h>
#include <vtkSphereSource.h>
#include <vtkSphereWidget2.h>
int main(int, char*[])
{
// Create a sphere/mapper/actor
auto sphereSource = vtkSmartPointer<vtkSphereSource>::New();
sphereSource->SetRadius(2.0);
auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(sphereSource->GetOutputPort());
auto actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(1.0, 0.0, 0.0);
actor->GetProperty()->SetOpacity(0.5);
// Create a renderer/render window/interactor
auto renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
renderer->SetBackground(0, 0, 0);
auto renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
auto renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
// Create widget
auto sphereWidget = vtkSmartPointer<vtkSphereWidget2>::New();
sphereWidget->SetInteractor(renderWindow->GetInteractor());
auto sphereRep = vtkSmartPointer<vtkSphereRepresentation>::New();
sphereWidget->SetRepresentation(sphereRep);
sphereRep->SetRadius(1);
sphereRep->UseBoundsOff();
sphereRep->HandleTextOff();
sphereRep->RadialLineOff();
sphereRep->GetSphereProperty()->SetOpacity(0.99);
sphereRep->GetSphereProperty()->SetColor(0.0, 1.0, 0.0);
sphereRep->SetRepresentationToSurface();
sphereWidget->On();
// Start the rendering loop
renderWindow->Render();
renderer->ResetCamera();
renderWindowInteractor->Start();
return 0;
}