ofxPostGlitch turns to gray screen

Hello OF community,

I’m having difficulties to make ofxPostGlitch work in my project. The example provided by the addon runs perfectly well after updating the project to OF 0.9.3 with the project-generator. Later in my project as soon as I toggle the shader with glitch.toggleFx(OFXPOSTGLITCH_CONVERGENCE); the screen turns completely gray. I’m currently using Xcode 7.3.

See if someone can throw some light on it : )

// main.cpp
#include "ofApp.h"
#include "ofAppGlutWindow.h"

int main() {
    ofAppGlutWindow window;
    ofSetupOpenGL(&window, 1920, 1080, OF_WINDOW);
    ofRunApp(new ofApp());
}
// ofApp.h
ofxPostGlitch glitch;
ofFbo view;
// ofApp.cpp
void ofApp:setup()
{
   // more code here...
    view.allocate(viewWidth, viewHeight, GL_RGBA);
    glitch.setup(&view);
   // more code here...
}

void ofApp::update() 
{
   // more code here...
    if (bDrawGui) ofSetDepthTest(bDrawGui);
    view.begin();
    ofClear(0,0,0,255);
    controlScenes.draw();
    view.end();
}

void ofApp::draw()
{
    glitch.generateFx();    
    ofSetColor(255);
    view.draw(0, viewY, viewWidth, viewHeight);

   // more code here...
}

Solved. I had to modify the following lines of the addon:

			ShadingBuffer.begin();
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
			ofRect(0, 0, buffer_size.x, buffer_size.y);
			ShadingBuffer.end();
			shader[i].end();

by instead:

			ShadingBuffer.begin();
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            targetBuffer->draw(0, 0, buffer_size.x, buffer_size.y);
			ShadingBuffer.end();
			shader[i].end();

Cheers.

1 Like

Any idea why that might be @valillon? I’ve got all the ofxPostGlitch effects working fine with 0.9.3 and xcode 7.3. I’ve changed ofRect to ofDrawRectangle but that shouldn’t make a difference really.

Hi @clem, the example in ofxPostGlitch is working perfectly fine. It was not working in my implementation. Concretely it stopped working after adding a shader at the beginning of my ofFbo view:

// Definition of controlScenes.draw();
void myControlSceneClass::draw()
{
   background.draw();   // This a ofShader drawn inside an custom class' method
   camera.begin();
   ... // some drawings here
   camera.end();
}

I do not why but it seemed that the line in ofxPostGlitch.cpp:

shader[i].setUniformTexture("image",*targetBuffer,0);

did not feed properly ShadingBuffer by simply drawing ofDrawRectangle(). It displayed a gray rectangle across the entire screen. Instead I forced to draw/buffer targetBuffer (targeted view) into ShaderBuffer and it worked out !!