[vtkusers] how to render VTK into user provided FBO
Max Chen
trlsmax at gmail.com
Mon Dec 3 22:35:13 EST 2018
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
More information about the vtkusers
mailing list