Re: how to render VTK into user provided FBO
Ken Martin via vtkusers <[email protected]>
| Newsgroups | gmane.comp.lib.vtk.user |
|---|---|
| Message-ID | <CANXz0Sb83L3bd1OtG1e8cORY_uvdT8KHXeHsdiwr69vrf-pVtg@mail.gmail.com> |
Try binding your FBO and context and then use InitializeFromCurrentContext. That has some logic to record the current FBO and use it for subsequent operations. That might do what you want. - Ken On Mon, Dec 3, 2018 at 10:35 PM Max Chen <[email protected]> wrote: > 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 > -- Ken Martin PhD Distinguished Engineer Kitware Inc. 101 East Weaver Street Carrboro, North Carolina 27510 USA This communication, including all attachments, contains confidential and legally privileged information, and it is intended only for the use of the addressee. Access to this email by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, distribution or any action taken in reliance on it is prohibited and may be unlawful. If you received this communication in error please notify us immediately and destroy the original message. Thank you. _______________________________________________ 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