How to use ofThread for drawing shape?

I’m trying to show the creation of a circle or line with some delay, but I’m stuck here.

class CircleThread : public ofThread
{
public:
	void threadedFunction()
	{
		while (isThreadRunning())
		{
	        lock();
			ofDrawCircle(100, 100, 50);
            ofSleepMillis(100);
			unlock();
		}
	}
};

The above code is crashing

Hi! Well, you don’t. opengl only has one context/“thread”, so you can’t draw call, use textures, etc. on threads. Those are CPU threads.

There a lot of add-ons for timers, timelines and animation systems, etc… But my guess is: you are over complicating things a bit. Start with a simple int/float, a bool and if statement.

Thanks for the replay, can you suggest some addons? @hubris

Hi, you can make a simple timer.
declare in your ofApp.h file:

uint64_t startTime;

then in ofApp.cpp

void ofApp::setup(){
startTime = ofGetElapsedTimeMillis();
}
void ofApp::draw(){
if(ofGetElapsedTimeMillis() - startTime > 1000) // change 1000 for the value you actually want.
{
ofDrawCircle(x,x,x);
}
}