jvcleave / ofxImGui

Use ImGui in openFrameworks
300 stars 123 forks source link

how to use dynamic textures #30

Closed carlesgutierrez closed 8 years ago

carlesgutierrez commented 8 years ago

Hi, Im trying to use this addon to show dynamic images in the GUi. For this Im using the texture inside of an FBO. Not sure how i should link or bind the texture to resolve this.

Here is my code. Texture is visible in the Draw app but not inside the GUI. May be some of you know how to do it properly. Cheers.

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
    myFBO.allocate(255, 255);
    myGui.setup();
}

//--------------------------------------------------------------
void ofApp::update(){

    myFBO.begin();
    ofSetColor(255);
    ofRect(0, 0, 255, 255);
    ofSetColor(0);
    ofEllipse(ofVec2f(mouseX, mouseY), 10, 10);
    myFBO.end();

}

//--------------------------------------------------------------
void ofApp::draw(){

    ofSetColor(255);

    myFBO.draw(255, 255, 255, 255);

    //required to call this at beginning
    myGui.begin();

    ImGui::Text("Hello");
    ImGui::Image((ImTextureID)(uintptr_t)myFBO.getTexture().getTextureData().textureID, ImVec2(255, 255));

    //required to call this at end
    myGui.end();

}
jvcleave commented 8 years ago

you have to create the FBO a bit differently - see this

https://github.com/jvcleave/ofxImGui/blob/develop/example-experimental/src/ofApp.cpp#L59

carlesgutierrez commented 8 years ago

Thanks that works perfect, and works for any size( Not only powered 2 texture dimensions )

armdz commented 6 years ago

Hi! Im having the same problem with dynamics textures, and the link that @jvcleave provides, won't work. How its the method to solve that problem ? (I tried setting the fbo as TEXTURE_2D, but then that fbo won't work in shaders)

Thanks! pd: great work! love this gui implementation.

jvcleave commented 6 years ago

@armdz here is a version of that project's source files

https://gist.github.com/jvcleave/47fc93217a24474abc787dbf5facecb2