<div dir="ltr"><div>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.</div><div><br></div><div>- Ken<br></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Dec 3, 2018 at 10:35 PM Max Chen <<a href="mailto:trlsmax@gmail.com">trlsmax@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
I want VTK render into a FBO I created and use the texture attached to this<br>
FBO to render into a glfw window.<br>
<br>
I tried this :<br>
create a class from vtkExternalOpenGLRenderWindow so I can modify the<br>
protected member.<br>
<br>
class MyRW : public vtkExternalOpenGLRenderWindow<br>
{<br>
public:<br>
        void SetFBO(unsigned int fbo, unsigned int tex, unsigned int w, unsigned<br>
int h);<br>
};<br>
<br>
void MyRW::SetFBO(unsigned int fbo, unsigned int tex, unsigned int w,<br>
unsigned int h)<br>
{<br>
<br>
        this->SetBackLeftBuffer(GL_COLOR_ATTACHMENT0);<br>
        this->SetFrontLeftBuffer(GL_COLOR_ATTACHMENT0);<br>
        this->SetBackBuffer(GL_COLOR_ATTACHMENT0);<br>
        this->SetFrontBuffer(GL_COLOR_ATTACHMENT0);<br>
<br>
        this->Size[0] = w;<br>
        this->Size[1] = h;<br>
        this->NumberOfFrameBuffers = 1;<br>
        this->DepthRenderBufferObject = 0;<br>
        this->FrameBufferObject = static_cast<unsigned int>(fbo);<br>
        this->TextureObjects[0] = static_cast<unsigned int>(tex);<br>
        this->OffScreenRendering = 1;<br>
        this->OffScreenUseFrameBuffer = 1;<br>
        this->Modified();<br>
}<br>
<br>
I also pass the glfw window pointer to vtkCommand::WindowMakeCurrentEvent.<br>
<br>
In the glfw loop :<br>
<br>
        // render into FBO<br>
        glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);<br>
        myvtk->render();<br>
        glBindFramebuffer(GL_FRAMEBUFFER, 0);<br>
<br>
        // use the texture<br>
        glEnable(GL_TEXTURE_2D);<br>
        glBindTexture(GL_TEXTURE_2D, m_tex);<br>
        unsigned int e = glGetError();<br>
        glColor4f(1, 1, 1, 1);<br>
        glBegin(GL_QUADS);<br>
        glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, 0);<br>
        glTexCoord2f(1.0, 0.0); glVertex3f(1.0, -1.0, 0);<br>
        glTexCoord2f(1.0, 1.0); glVertex3f(1.0, 1.0, 0);<br>
        glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0, 0);<br>
        glEnd();<br>
        glBindTexture(GL_TEXTURE_2D, 0);<br>
        glDisable(GL_TEXTURE_2D);<br>
<br>
        // draw imgui <br>
        ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());<br>
<br>
but it did not work, window is flickering and imgui just disappear.<br>
<br>
I setup a cmake test project in github, please help.<br>
<a href="https://github.com/trlsmax/imgui-vtk" rel="noreferrer" target="_blank">https://github.com/trlsmax/imgui-vtk</a> <<a href="https://github.com/trlsmax/imgui-vtk" rel="noreferrer" target="_blank">https://github.com/trlsmax/imgui-vtk</a>>  <br>
<br>
<br>
<br>
--<br>
Sent from: <a href="http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html" rel="noreferrer" target="_blank">http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html</a><br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">https://public.kitware.com/mailman/listinfo/vtkusers</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Ken Martin PhD<div>Distinguished Engineer<br><span style="font-size:12.8px">Kitware Inc.</span><br></div><div>101 East Weaver Street<br>Carrboro, North Carolina<br>
27510 USA<br><br><div><span style="font-size:10pt;font-family:Tahoma,sans-serif">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.</span></div></div></div></div></div></div></div>