[vtkusers] how to render VTK into user provided FBO

Max Chen trlsmax at gmail.com
Tue Dec 4 23:04:25 EST 2018


Thank you. Now I have a working prototype.
But I get a strangle issue, I can only resize the offscreen
vtkGenericOpenGLRenderWindow 3 times, otherwise I get error like :
ERROR: In E:\projects\VTK-8.1.2\Rendering\OpenGL2\vtkOpenGLActor.cxx, line
107
vtkOpenGLActor (0B2C4C10): failed after Render 1 OpenGL errors detected
 0:(1285)out of memory

the resize code is :
void MyVTKRenderer::UpdateSize(unsigned int w, unsigned int h)
{
	if (w == m_Width && h == m_Height)
		return;

	if (w == 0 || h == 0)
		return;

	m_Width = w;
	m_Height = h;

	// resize the render window
	m_vtkRenderWindow->SetSize(m_Width, m_Height);
	m_vtkRenderWindow->FullScreenOn();
	m_vtkRenderWindow->OffScreenRenderingOn();
	//m_vtkRenderWindow->SetMultiSamples(0);
	m_vtkRenderWindow->Modified();
	m_vtkRenderWindowInteractor->UpdateSize(m_Width, m_Height);
	m_vtkRenderWindowInteractor->Modified();
	m_IsInited = false;

	// delete old fbo
	glDeleteBuffers(1, &m_fbo);
	glDeleteBuffers(1, &m_rbo);
	glDeleteTextures(1, &m_tex);

	// create a texture object
	glGenTextures(1, &m_tex);
	glBindTexture(GL_TEXTURE_2D, m_tex);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_Width, m_Height, 0, GL_RGB,
GL_UNSIGNED_BYTE, 0);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glBindTexture(GL_TEXTURE_2D, 0);
	// create a renderbuffer object to store depth info
	glGenRenderbuffers(1, &m_rbo);
	glBindRenderbuffer(GL_RENDERBUFFER, m_rbo);
	glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Width,
m_Height);
	glBindRenderbuffer(GL_RENDERBUFFER, 0);

	// create a framebuffer object
	glGenFramebuffers(1, &m_fbo);
	glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
m_tex, 0);
	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
GL_RENDERBUFFER, m_rbo);
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

Another issue is , these code can't work on VTK-8.2 rc1



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list