How to draw an ofFbo in ofxImGui window

#1

Hello,

I try to draw an FBO in a ImGui window.

Im’ using OF 10.1, ofxImGui with ImGui 1.65 or 1.72b

Follow is the code.

for Setup

gui.setup();

// load image
fn << "./gradients/Vice City.jpg";
imgId = gui.loadImage(fn.str());

fbo.allocate(400, 400);

for Draw

fbo.begin();
    ofClear(255);
    ofSetColor(255, 0, 0);
    ofCircle(200, 200, 60);
  fbo.end();

  fbo.draw(0, 0);

  DrawUI();

for DrawUI

gui.begin();

  ImGui::Begin("Image");
    ImGui::Image(GetImTextureID(imgId), ImVec2(400, 400));
  ImGui::End();

  ImGui::Begin("Fbo");
    ImGui::Image(GetImTextureID(fbo.getTexture()), ImVec2(400, 400));
  ImGui::End();

  ImGui::Begin("Button FBO");
    ImGui::ImageButton(GetImTextureID(imgId), ImVec2(200, 50));
    ImGui::ImageButton(GetImTextureID(fbo.getTexture()), ImVec2(200, 50));
  ImGui::End();

  gui.end();

The Fbo draw correctly in the background (the red circle), but not in ImGui window or button.
Instead it shows the font map ?

See the screen capture.

I’m rather new to OF and OpenGL, I used to work in Unity.
Any idea on what I’m doing wrong ?

Tank’s,

Constant

#2

Welcome Constant.

I’ve found it works with this kind of FBO:

ofFbo::Settings fboSettings ;
fboSettings.width = width ;
fboSettings.height = height ;
fboSettings.internalformat = GL_RGBA ;
fboSettings.textureTarget = GL_TEXTURE_2D ;
previewFbo.allocate( fboSettings ) ;

then

previewFbo.begin() ;
cam->draw( 0.f, 0.f ) ;
previewFbo.end() ;
ImTextureID textureID = ( ImTextureID )( uintptr_t )previewFbo.getTexture().getTextureData().textureID ;
auto size = ImGui::GetContentRegionAvail() ; // for example
ImGui::Image( textureID, size ) ;
2 Likes
#3

Hi Lilive,

Thank’s very much, this solve my issue !
I guess the default allocate does’nt set the same internalFormat or textureTarget.

Have a good day.