how to render VTK into user provided FBO

Max Chen <[email protected]>
Newsgroups gmane.comp.lib.vtk.user
Message-ID <[email protected]>
Hi all,

I want VTK render into a FBO I created and use the texture attached to this
FBO to render into a glfw window.

I tried this :
create a class from vtkExternalOpenGLRenderWindow so I can modify the
protected member.

class MyRW : public vtkExternalOpenGLRenderWindow
{
public:
	void SetFBO(unsigned int fbo, unsigned int tex, unsigned int w, unsigned
int h);
};

void MyRW::SetFBO(unsigned int fbo, unsigned int tex, unsigned int w,
unsigned int h)
{

	this->SetBackLeftBuffer(GL_COLOR_ATTACHMENT0);
	this->SetFrontLeftBuffer(GL_COLOR_ATTACHMENT0);
	this->SetBackBuffer(GL_COLOR_ATTACHMENT0);
	this->SetFrontBuffer(GL_COLOR_ATTACHMENT0);

	this->Size[0] = w;
	this->Size[1] = h;
	this->NumberOfFrameBuffers = 1;
	this->DepthRenderBufferObject = 0;
	this->FrameBufferObject = static_cast<unsigned int>(fbo);
	this->TextureObjects[0] = static_cast<unsigned int>(tex);
	this->OffScreenRendering = 1;
	this->OffScreenUseFrameBuffer = 1;
	this->Modified();
}

I also pass the glfw window pointer to vtkCommand::WindowMakeCurrentEvent.

In the glfw loop :

	// render into FBO
	glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
        myvtk->render();
	glBindFramebuffer(GL_FRAMEBUFFER, 0);

	// use the texture
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, m_tex);
	unsigned int e = glGetError();
	glColor4f(1, 1, 1, 1);
	glBegin(GL_QUADS);
	glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, 0);
	glTexCoord2f(1.0, 0.0); glVertex3f(1.0, -1.0, 0);
	glTexCoord2f(1.0, 1.0); glVertex3f(1.0, 1.0, 0);
	glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0, 0);
	glEnd();
	glBindTexture(GL_TEXTURE_2D, 0);
	glDisable(GL_TEXTURE_2D);

        // draw imgui 
        ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());

but it did not work, window is flickering and imgui just disappear.

I setup a cmake test project in github, please help.
https://github.com/trlsmax/imgui-vtk <https://github.com/trlsmax/imgui-vtk>  



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.