@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