-
-
Save vvzen/2d262406c0b19893c65c48855219792b to your computer and use it in GitHub Desktop.
Command line arguments in openFrameworks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
#include "ofAppGlutWindow.h" | |
//======================================================================== | |
// Command line arguments | |
// argc : argument count.. how many args? | |
// argv : arguments vector (array, in reality) | |
int main(int argc, char *argv[]){ | |
// vector for storing args | |
vector<string> myArgs; | |
if(argc > 1){ | |
for(int i = 0; i < argc; i++){ | |
//cout << "arg num " << i << " : " << argv[i] << endl; | |
myArgs.push_back(argv[i]); | |
} | |
} | |
// create a window | |
ofAppGlutWindow window; | |
// set width, height, mode (OF_WINDOW or OF_FULLSCREEN) | |
ofSetupOpenGL(&window, 1024, 768, OF_WINDOW); | |
ofApp *app = new ofApp(); | |
// add args to app instance | |
app->arguments = myArgs; | |
ofRunApp(app); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
//-------------------------------------------------------------- | |
void ofApp::draw(){ | |
ofBackground(0); | |
ofSetColor(0,255,0); | |
ofDrawBitmapString("App arguments: ", 20.0f, 20.0f); | |
ofSetColor(255); | |
for (int i = 0; i < arguments.size(); i++){ | |
ofDrawBitmapString(arguments[i], 20.0f, 60.0f + (20*i)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofMain.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 windowResized(int w, int h); | |
void dragEvent(ofDragInfo dragInfo); | |
void gotMessage(ofMessage msg); | |
// Vector for storing our args | |
vector<string> arguments; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open -n ./emptyExampleDebug.app/ --args --myargs 1 2 3 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment