I am trying to render offscreen with EGL but I keep geting segmentation fault.
Thank you,
std::cerr << "Colours" << std::endl;
// Setup offscreen rendering
vtkNew<vtkNamedColors> colors;
std::cerr << "Pre-GraphicsFac Ok" << std::endl;
vtkNew<vtkGraphicsFactory> graphics_factory;
graphics_factory->SetOffScreenOnlyMode(1);
graphics_factory->SetUseMesaClasses(1);
std::cerr << "Pos-GraphicsFac Ok" << std::endl;
// Create a sphere
vtkNew<vtkSphereSource> sphereSource;
sphereSource->SetThetaResolution(75);
sphereSource->SetPhiResolution(75);
// vtkNew<vtkTexture> texture;
// texture->SetInputConnection(sphereSource->GetOutputPort());
std::cerr << "Sphere Created Ok" << std::endl;
// Create a mapper and actor
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(sphereSource->GetOutputPort());
// Apply the texture
vtkNew<vtkTexture> texture;
texture->SetInputConnection(sphereSource->GetOutputPort());
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(colors->GetColor3d("White").GetData());
actor->SetMapper(mapper);
actor->SetTexture(texture);
// A renderer and render window
vtkNew<vtkOpenGLRenderer> renderer;
vtkNew<vtkEGLRenderWindow> renderWindow;
std::cerr << "Number of Devices: "<< renderWindow->GetNumberOfDevices() << std::endl;
renderWindow->MakeCurrent();
renderWindow->SetOffScreenRendering(1);
renderWindow->OffScreenRenderingOn();
renderWindow->SetShowWindow(false);
renderWindow->WindowInitialize();
renderWindow->MakeCurrent();
renderWindow->AddRenderer(renderer);
renderer->AddActor(actor);
renderer->SetBackground(colors->GetColor3d("SlateGray").GetData());
std::cerr << "Render Created Ok" << std::endl;
renderWindow->Render();
std::cerr << "Render Window Created Ok" << std::endl;
// Add the actors to the scene
// Perform offscreen rendering
std::cerr << "Actor Added Ok" << std::endl;
std::cerr << "Render Ok" << std::endl;
vtkNew<vtkWindowToImageFilter> windowToImageFilter;
windowToImageFilter->SetInput(renderWindow);
windowToImageFilter->Update();
std::cerr << "Render-Window to image Ok" << std::endl;
vtkNew<vtkPNGWriter> writer;
writer->SetFileName("/home/3484681/Área de Trabalho/PRISMAMESH/createmesh/screenshot.png");
writer->SetInputConnection(windowToImageFilter->GetOutputPort());
writer->Write();