Framebuffer Object creation not working in Python

I am developing a feature for FURY, a python graphics library I am working on (that is entirely built with vtk), and this feature has FBOs as core for its functionality, as they will be used for multiple drawings. Well, I learnt how to use the vtkOpenGLFramebufferObject class, however, I have been stuck over one week on the FBO generation part. As the documentation explains, the following steps should be taken for the FBO generation:

fbo->SetContext(renWin);
fbo->SaveCurrentBindingsAndBuffers();
fbo->PopulateFramebuffer(width, height);
 
...
 
fbo->RestorePreviousBindingsAndBuffers();

And, supposing the steps are the same in python, I did it in my python code:

FBO = vtk.vtkOpenGLFramebufferObject()
FBO.DebugOn()
FBO.GlobalWarningDisplayOn() 

#print(scene.GetRenderWindow().SupportsOpenGL()) # For some reason, this single call makes the program not crash, but the FBO generation still does not work 

print(FBO.IsSupported(scene.GetRenderWindow())) # the context supports the required extensions (outputs True)

FBO.SetContext(scene.GetRenderWindow()) #  >>>>>>THE PROBLEM IS HERE<<<<<<<
FBO.PopulateFramebuffer(width, height) # Crashes here

For some reason, the program just seems to “skip” the FBO generation with no error output (even after I set the warning displays and debug mode both on for every class I had that is involved on the process) and if the PopulateFramebuffer() method is called after, it crashes. I figured the FBO was not being created as later I printed its index, that is returned 0, showing the FBO was not generated by glGenFramebuffers(). I could track down the problem to FBO.SetContext() method, and now I am just trying to understand whether, looking at the implementation of it, the program is getting to the FBO->CreateFBO() method, or returning it before this part. Below, how SetContext() and CreateFBO() are implemented, according to VTK’s repo:

void vtkOpenGLFramebufferObject::SetContext(vtkRenderWindow *rw)
{
  vtkOpenGLRenderWindow *renWin = static_cast<vtkOpenGLRenderWindow *>(rw);

  // avoid pointless re-assignment
  if (this->Context==renWin)
  {
    return;
  }

  this->ResourceCallback->RegisterGraphicsResources(renWin);

  // all done if assigned null
  if (!renWin)
  {
    return;
  }
  // check for support
  if (!this->LoadRequiredExtensions(renWin))
  {
    vtkErrorMacro("Context does not support the required extensions");
    return;
  }
  // initialize
  this->Context=renWin;
  this->Context->MakeCurrent();
  this->CreateFBO();
}
void vtkOpenGLFramebufferObject::CreateFBO()
{
  this->FBOIndex=0;
  GLuint temp;
  glGenFramebuffers(1,&temp);
  vtkOpenGLCheckErrorMacro("failed at glGenFramebuffers");
  this->FBOIndex=temp;
}

I wondered if it had to deal with the Context being null or not supporting the required extensions, but the first does not make sense as it is later used normally to render a single rectangle, and the second is not the problem as well as the FBO.IsSupported(scene.GetRenderWindow()) returns True.

What could be the issue here?

1 Like

Ok, so apparently, I found a solution to that problem. I did not realise I needed to initialize the window interactor I was using in the scene, so the context itself did not seem to have existed to be passed to the FBO. After initializing it (befor the FBO declaration) it worked fine and generated a FBO index. Sorry for that, I am kinda new to VTK, so that was a rookie mistake, that I am going to leave here if anyone goes through the same problem :stuck_out_tongue: