loopOnce()? noLoop() equivalent?

The documentation is not very clear about the uses for this loopOnce(). ofMainLoop | openFrameworks

I came across this post on how to draw once, How to loopOnce but I my testing it didn’t result in anything being drawn.

void ofApp::setup(){
	ofSetBackgroundAuto(false);
}

//--------------------------------------------------------------
void ofApp::draw(){
	if(ofGetFrameNum() == 0){
		ofDrawBitmapString(ofToString(ofGetFrameNum()), 20, 20);
		ofDrawBitmapString("LOOPED ONE", 0, 40);
		ofDrawRectangle(200, 200, 200, 200);
	} else {
//		 ofDrawBitmapString(ofToString(ofGetFrameNum()), 20, 20);
//		 ofDrawBitmapString("CONTINUED EXECUTING", 20, 40);
	}
}

I feel a little dumb here, I am just looking for a noLoop() equivalent. noLoop() / Reference / Processing.org

I will let someone else confirm there is no explicit toggle such as processing’s noLoop() in OF, but your test reveals a form of problem with the renderer, perhaps some caching or buffering issue. Like you I get nothing with ofGetFrameNum() == 0 but ofGetFrameNum() == 3 creates flickering effect of the frame (here on macOS13.1 at least). You are invited to report that as an issue: Issues · openframeworks/openFrameworks · GitHub

But notwithstanding the above, depending on your end goal perhaps writing to an FBO once would be a better approach? They are allocated in dedicated VRAM, whereas the framebuffer/window is being tickled by the App, openGL/glfw, the OS…

1 Like

Hi @08_objekt , I agree with burton’s comments. I don’t think OF has an equivalent to Processing’s noLoop(). It might be helpful if you post a bit more about what you’d like to do. OF is designed to run an application with an update/draw cycle.

I think there is a slight delay in between when an app starts the update/draw cycle, and when the window is ready for rendering. I ran your code on a m1 Mac and needed 3+ frames before it rendered something. The number of frames might be higher for other systems, or lower for lower frame rates.

I had a flickering too, which seems to be related to the double buffering for the window. This stopped the flicker for me:

// in main.cpp
    ofGLFWWindowSettings settings;
    settings.doubleBuffering = false;

You might also have a look at rendering once into an ofFbo, and then drawing it each cycle. An ofFbo will retain the previous rendering unless ofClear() is called. So something like this:

// in ofApp.h
    ofFbo fbo;

// in ofApp::setup()
    fbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGBA);
    fbo.begin();
    // draw something
    fbo.end();

// in ofApp::draw()
    fbo.draw(0.f, 0.f);

Yes thanks. ofFbo did allow for this.