LoginSignup
8
8

More than 5 years have passed since last update.

openFrameworksのソースコードを1ファイルにする

Last updated at Posted at 2016-01-13

やりたいこと

簡単なコードを書くのにmain.cpp, ofApp.cpp, ofApp.hファイル分けて行ったり来たりするのがめんどくさいので、アプリケーションの記述をmain.cppに集中させたい。

main.cpp

main.cppに全部書く。

// main.cpp
#include "ofMain.h"

class ofApp : public ofBaseApp{

public:
    void setup(){
        ofBackground(0);
    }
    void update(){
       x += direction;
       if( x > ofGetWidth() || x < 0.0 ){
          direction *= -1; // bounce
        }
    }
    void draw(){
        ofDrawCircle(x, ofGetHeight()/2, 100);
   }
     // Define members here.
    float x = 0.0, direction = 8.0;
};

//========================================================================
int main( ){
    ofSetupOpenGL(1024,768,OF_WINDOW);          // <-------- setup the GL context

    // this kicks off the running of my app
    // can be OF_WINDOW or OF_FULLSCREEN
    // pass in width and height too:
    ofRunApp(new ofApp());

}

ofApp.hとofApp.cpp

必要ないのでファイルごと削除する。

8
8
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
8
8