tiagosr / ofxShadertoy

Addon for openFrameworks that sets up and loads Shadertoy (http://www.shadertoy.com) shaders
83 stars 15 forks source link

using ofFbo .getTexture() #6

Open stephanschulz opened 6 years ago

stephanschulz commented 6 years ago

it's me again.

I was successful loading an image in to my polarGrid example inside setup().

I am now trying to generate an ofFbo and pass it's texture to the shader during update(). But it's always black. If I do the work around as in the below code things work. But it seems silly to have to pass FBO to pix, to tex.

Ideally I would be able to just call mainFbo.getTexture()

Any ideas what I am doing wrong?

void ofApp::update(){

    if(mainFbo.isAllocated() == false){
        img.allocate(1024, 768, OF_IMAGE_COLOR);
        tex.allocate(img.getWidth(), img.getHeight(), GL_RGBA, false); 
        mainFbo.allocate(1024,768, GL_RGBA, false);
    }

    mainFbo.begin();
    ofClear(255,255,255,0);
    ofSetColor(255, 0, 0,255);
    ofDrawCircle(mouseX, mouseY, 400);
    mainFbo.end();

//    shadertoy.setTexture(0, mainFbo.getTexture());

    ofPixels pix;
    mainFbo.readToPixels(pix);
    img.setFromPixels(pix);
    tex.loadData(img.getPixels());
    shadertoy.setTexture(0, tex);
}
tiagosr commented 6 years ago

There's nothing wrong in practice with your code - FBOs used to have the same interface as textures in 0.8.x, but for 0.9.x oF has changed their interface, and this means the round-trip is needed for now. The multiple-buffer work I'm preparing should fix this and enable direct usage of the FBO object.

Issue #4 is pretty similar to this, and I should be able to resolve it soon.

Cheers!

micuat commented 6 years ago

I found the solution. When you allocate fbo, you need to disable arbtex

    ofDisableArbTex();
    fbo.allocate(1024, 768, GL_RGBA32F);

or you can

    ofFboSettings fs;
    fs.width = 1024;
    fs.height = 768;
    fs.internalformat = GL_RGBA32F;
    fs.textureTarget = GL_TEXTURE_2D;
    fbo.allocate(fs);