Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

How to get ofFbo data without drawing to screen

$
0
0

@khho wrote:

I want to blur an image using shader, and then save the resulting image. I started from an example of openframework v0.10.1, that is, shader/09_gaussianBlurFilter. I added an ofPixels (called inputPixels) and ofImage (called outputImage) to achieve my objective. Below are my codes, where I added comments for what I added by “added by me.”

The program works. It can save an image file, same as the screen shows. However, I don’t want to draw anything to screen. I wanted to blur an image and save the result in a more clean way. So I tried to remove “fboBlurOnePass.draw(0, 0);” and “fboBlurTwoPass.draw(0, 0);.” However, the program failed to save a meaningful image file if I remove the two.

I was wondering if someone can tell me how to modify the codes, so as to blur an image without drawing anything to screen. Thank you very much.

void ofApp::draw(){
    float blur = ofMap(mouseX, 0, ofGetWidth(), 0, 4, true);
    
    //----------------------------------------------------------
    fboBlurOnePass.begin();
    
    shaderBlurX.begin();
    shaderBlurX.setUniform1f("blurAmnt", blur);

    image.draw(0, 0);
    shaderBlurX.end();
    fboBlurOnePass.end();
    
    //----------------------------------------------------------
    fboBlurTwoPass.begin();
    
    shaderBlurY.begin();
    shaderBlurY.setUniform1f("blurAmnt", blur);
    
    fboBlurOnePass.draw(0, 0);
    fboBlurOnePass.readToPixels(inputPixels); // added by me
    shaderBlurY.end();
    fboBlurTwoPass.end();
    
    //----------------------------------------------------------
    ofSetColor(ofColor::white);
    fboBlurTwoPass.draw(0, 0);
    fboBlurTwoPass.readToPixels(inputPixels); // added by me

    outputImage.setFromPixels(inputPixels); // added by me
    outputImage.saveImage("screenshot.png"); // added by me
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles