Commit f5c800d2 authored by Max Smolens's avatar Max Smolens
Browse files

vtkWin32OpenGLRenderWindow: fix setting window size for offscreen rendering

This commit fixes a problem where rendering offscreen with
vtkWin32OpenGLRenderWindow ignores the size set by SetSize(). This is seen when
using vtkOpenGLRenderWindow::CreateHardwareOffScreenWindow()'s framebuffer
object offscreen rendering implementation.
parent 1a876943
......@@ -36,7 +36,7 @@ endif()
if(WIN32 AND NOT VTK_USE_X)
vtk_add_test_cxx(${vtk-module}CxxTests render_window_tests
TestWin32OpenGLRenderWindow.cxx NO_VALID)
TestWin32OpenGLRenderWindow.cxx)
endif()
vtk_add_test_cxx(${vtk-module}CxxTests ogl_tests
......
......@@ -20,48 +20,64 @@
#include "vtkActor.h"
#include "vtkConeSource.h"
#include "vtkWin32OpenGLRenderWindow.h"
#include <vtkConeSource.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkNew.h>
#include "vtkPolyDataMapper.h"
#include "vtkNew.h"
#include "vtkRegressionTestImage.h"
//This tests if the offscreen rendering works
static bool TestWin32OpenGLRenderWindowOffScreen(vtkWin32OpenGLRenderWindow* renderWindow)
int TestWin32OpenGLRenderWindow(int argc, char* argv[])
{
//Create a cone
vtkNew<vtkConeSource> coneSource;
coneSource->Update();
vtkNew<vtkRenderWindow> renWin;
if (!vtkWin32OpenGLRenderWindow::SafeDownCast(renWin.GetPointer()))
{
std::cout << "Expected vtkRenderWindow to be a vtkWin32OpenGLRenderWindow"
<< std::endl;
return EXIT_FAILURE;
}
//Create a mapper and actor
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(coneSource->GetOutputPort());
// Set multisamples to 0 to allow using
// vtkOpenGLRenderWindow::CreateHardwareOffScreenWindow() implementation
// (see check near top of function)
renWin->SetMultiSamples(0);
vtkNew<vtkActor> actor;
actor->SetMapper(mapper.GetPointer());
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin.GetPointer());
//Create a renderer, render window, and interactor
vtkNew<vtkRenderer> renderer;
renderWindow->AddRenderer(renderer.GetPointer());
renWin->AddRenderer(renderer.GetPointer());
//Add the actors to the scene
renderer->AddActor(actor.GetPointer());
renderer->SetBackground(.3, .2, .1); // Background color dark red
vtkNew<vtkConeSource> coneSource;
coneSource->Update();
//Render and interact
renderWindow->SetOffScreenRendering(1);
renderWindow->SetSize(100,100);
renderWindow->Render();
return 1;
}
vtkNew<vtkPolyDataMapper> coneMapper;
coneMapper->SetInputConnection(coneSource->GetOutputPort());
int TestWin32OpenGLRenderWindow(int vtkNotUsed(argc), char* vtkNotUsed(argv)[])
{
vtkWin32OpenGLRenderWindow* renderWindow(NULL);
vtkNew<vtkActor> coneActor;
coneActor->SetMapper(coneMapper.GetPointer());
renderer->AddActor(coneActor.GetPointer());
int width = 100;
int height = 75;
float scale = 4.0f;
int scaledWidth = width * scale;
int scaledHeight = height * scale;
vtkNew<vtkRenderWindow> renderWindowBase;
renderWindow = vtkWin32OpenGLRenderWindow::SafeDownCast(renderWindowBase.GetPointer());
renderer->SetGradientBackground(1);
renderer->SetBackground(0.0, 0.37, 0.62);
renderer->SetBackground2(0.0, 0.62, 0.29);
renWin->SetSize(width, height);
renWin->Render();
TestWin32OpenGLRenderWindowOffScreen(renderWindow);
// Render offscreen at a larger size
renWin->SetOffScreenRendering(1);
renWin->SetSize(scaledWidth, scaledHeight);
renWin->Render();
return EXIT_SUCCESS;
int retVal = vtkRegressionTestImage(renWin.GetPointer());
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return !retVal;
}
......@@ -1491,6 +1491,10 @@ void vtkWin32OpenGLRenderWindow::CreateOffScreenWindow(int width,
this->CreateOffScreenDC(width, height, dc);
DeleteDC(dc);
}
else
{
this->Mapped = 0;
}
this->CreatingOffScreenWindow = status;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment