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

Flickering, ofSetBackgroundAuto(false), and no double buffering?

$
0
0

@smonaghan000 wrote:

Hello all - new user Sean here. I’m working through the ofBook, and setting ofSetBackgroundAuto(false); per the “Graphics/Brushes from Basic Shapes” chapter. I’m seeing this kind of flickering when running the app. Some searching led me to some older posts like ofSetBackgroundAuto flicker, Flickering with ofSetBackgroundAuto and others, and I also came across the PR #1170, and the addition of window.setDoubleBuffering(false); to the OF API. Lastly, and probably most importantly I see arturo’s recent post Xcode 10 / mojave issues, so I know my mileage may vary here, but I’ll ask anyway. I’m struggling to find the right way to configure my app to eliminate this flicker. Am I using the OF API correctly? Thanks for any insight and guidance.

p.s. I’ll also add that, based on what I’m seeing in more advanced OF examples, I realize that ofSetBackgroundAuto(false) is not the best way to achieve this kind of accumulative drawing effect, but I’m mostly just curious and would like to gain a better understand things. Thanks!

main.cpp

#include "ofMain.h"
#include "ofApp.h"

int main(){
	ofGLFWWindowSettings settings;
	settings.setSize(1024, 768);
	settings.setPosition(ofVec2f(300,300));
	settings.resizable = true;

	// The OF default results in flickering 
	settings.doubleBuffering = true;

	// My attempt to remove the flickering, but results in a black screen, where my drawing operations just won't display
	// settings.doubleBuffering = false;

	shared_ptr<ofAppBaseWindow> glfwWindow = ofCreateWindow(settings);
	shared_ptr<ofApp> app(new ofApp);
	ofRunApp(glfwWindow, app);
	ofRunMainLoop();
}

ofApp.cpp

#include "ofApp.h"

void ofApp::setup(){
    ofSetVerticalSync(true);
    ofSetFrameRate(60);
    ofBackground(0);
    ofSetBackgroundAuto(false);
}

void ofApp::draw(){
    if (ofGetMousePressed(OF_MOUSE_BUTTON_RIGHT)){
        ofBackground(0); // clear the screen please
    }else if (ofGetMousePressed(OF_MOUSE_BUTTON_LEFT)){
        ofSetColor(ofRandom(50, 255));
        ofSetRectMode(OF_RECTMODE_CENTER);
        int numRects = 10;
        for(int i=0;i<numRects;i++){
            ofSetColor(ofRandom(50, 255));
            float width = ofRandom(5,20);
            float height = ofRandom(5,20);
            float distance = ofRandom(35);
            float angle = ofRandom(ofDegToRad(360.0));
            float xOffset = cos(angle) * distance;
            float yOffset = sin(angle) * distance;
            ofDrawRectangle(ofGetMouseX() + xOffset, ofGetMouseY()+yOffset, width, height);
        }
   }
}

And some details about my setup

> of_v0.10.0_osx_release

> sw_vers
ProductName:	Mac OS X
ProductVersion:	10.13.6
BuildVersion:	17G65

> clang --version
Apple LLVM version 10.0.0 (clang-1000.11.45.2)
Target: x86_64-apple-darwin17.7.0

> xcodebuild -version
Xcode 10.0
Build version 10A255

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles