Drawing skipping first few frames?

Hi everybody,

I’m confused by the behaviour of the following, rather simple script:

ofApp.h :

#pragma once

#include "ofMain.h"

class ofApp : public ofBaseApp{
    
	public:
		void setup();
		void update();
		void draw();

    int x,;
};

ofApp.cpp :

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
    
    ofBackground(0);
    ofSetBackgroundAuto(false);

    x = 0;
}

//--------------------------------------------------------------
void ofApp::update(){

    x += 10;

}

//--------------------------------------------------------------
void ofApp::draw(){
    
    ofSetColor(255);
    ofDrawCircle(x, 10, 10);
     
}

Somehow it doesn’t seem to start drawing the first circle at (x: 10, y: 10), where it would touch the upper and right window border of the app?

My drawing coordinates seem to be on point! What am I missing here?

Thanks.

I think there’s always been some issues with ofSetBackgroundAuto(false) not working on the first frame on some graphics cards so it likely is a bit of a hack where the first few frames are cleared. I remember this hack from many years ago but I don’t remember anything about why we needed it.

instead of ofSetBackgroundAuto you can use an fbo, clear it in setup and not clear it in draw, you should see circles from the start. (although notes that since you add 10 in setup, the first circle should have an x position of 10 since update is called before draw)

1 Like

Thanks for your reply, @zach!

OK, noted!

When I use ofFbo, and clear it in ofApp::setup() with fbo.clear(), the entire drawing gets flipped on the horizontal axis, and the same error is now reproduced in the bottom left corner, instead of the top left corner.
However, when I comment fbo.clear() out, it works flawlessly, except that the background is now blue, instead of black!? Any ideas?

Thanks again. :slight_smile:

Seems like a cleared it wrong before! This solved it for me:

//--------------------------------------------------------------
void ofApp::setup(){
    
    ofBackground(0);
    //ofSetBackgroundAuto(false);

    x = 0;

    fbo.allocate(ofGetWidth(), ofGetHeight());
    fbo.begin();
    ofClear(0);
    fbo.end();
}

//--------------------------------------------------------------
void ofApp::update(){

    x += 10;

}

//--------------------------------------------------------------
void ofApp::draw(){
    fbo.begin();
    ofSetColor(255);
    ofDrawCircle(x, 10, 10);
    fbo.end();
    fbo.draw();
}