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

A threaded font loader?

$
0
0

@cuinjune wrote:

Hi, I'm trying to load ofTrueTypeFont in a different thread.
But If I try to load font on different thread, I get the following error.

I think it has to do with font using a texture, but I don't know how to disable using the texture like in ofImage there's setUseTexture(false);

Here's my code below.
In ofApp.h

class fontLoaderThread : public ofThread {

public:

    void loadFont(ofTrueTypeFont& font, const string &path, const int size)
    {
        _font = &font;
        _path = path;
        _size = size;
        startThread();
    }

private:

    ofTrueTypeFont *_font;
    string _path;
    int _size;

    void threadedFunction()
    {
        while (isThreadRunning()) {

            if (lock()) {

                _font->load(_path, _size);
                unlock();
                stopThread();
            }
        }
    }
};

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

		void keyPressed(int key);
		void keyReleased(int key);
		void mouseMoved(int x, int y);
		void mouseDragged(int x, int y, int button);
		void mousePressed(int x, int y, int button);
		void mouseReleased(int x, int y, int button);
		void mouseEntered(int x, int y);
		void mouseExited(int x, int y);
		void windowResized(int w, int h);
		void dragEvent(ofDragInfo dragInfo);
		void gotMessage(ofMessage msg);


fontLoaderThread loader;
ofTrueTypeFont font;

};

In ofApp.cpp

void ofApp::setup(){

    loader.loadFont(font, "/path/To/font.ttf", 30); //error here
}

Any suggestion?

Posts: 2

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles