LoginSignup
6
6

More than 5 years have passed since last update.

openFrameworksで日本語を表示する方法

Last updated at Posted at 2016-10-12

1. ofxTrueTypeFontUCを追加する

標準だとできないので、アドオンを追加する。
hironishihara/ofxTrueTypeFontUCからアドオン一式をダウンロードして、OF_ROOT/addonsに配置する。

2. 使用するフォントを追加する

使用したい日本語フォントをアプリの下のbin/dataとかに配置する。

3. コードを書く

まずヘッダーファイルでアドオンをインクルードして、インスタンスを作成する。

ofApp.h
#pragma once

#include "ofMain.h"
#include "ofxTrueTypeFontUC.h"

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);

    static const int fontSize = 19;
    static const int posX = 100;
    static const int posY = 100;
    ofxTrueTypeFontUC font;
};

次に、実際にフォントデータを読み込んで描画する。

ofApp.cpp
#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
    font.loadFont("fontName.otf", fontSize);
}

//--------------------------------------------------------------
void ofApp::draw(){
    font.drawString("こんにちは", posX, posY);
}
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6