Using DrawBitmapStirng() out of draw() function

Hello everyone. I would like to learn if it was possible to draw a string at the screen out of the ofApp::draw() method. I created an ofThread subclass and I want some of the drawing part to be done by the thread.
I tried to use the DrawBitmapString() function out of the ofApp::draw() method and it doesn’t seem to work.

Thanks in advance.

Hi @hkn_c,

I think you can declare a method in the subclass called drawString, such as this :

void subClassName::drawString(){
std::string stringToDraw = "words";
ofPushStyle();
ofSetColor(255);
ofDrawBitmapString(stringToDraw, {0,0});
ofPopStyle();
}

Then inside your ofApp::draw, you call this function from your external thread.

Hope this helps,

++

P

Draw calls afaik cannot be called from outside of the main thread. As well as anything that requires the use of the GPU (ofTexture for example).

You can refer to the chapter on Threads in ofBook, there’s a very good chapter there.

https://openframeworks.cc/ofBook/chapters/threads.html