Skip to content

Instantly share code, notes, and snippets.

@vvzen
Forked from baku89/OSX Example
Last active September 1, 2016 12:01
Show Gist options
  • Save vvzen/2d262406c0b19893c65c48855219792b to your computer and use it in GitHub Desktop.
Save vvzen/2d262406c0b19893c65c48855219792b to your computer and use it in GitHub Desktop.
Command line arguments in openFrameworks
#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);
}
#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));
}
}
#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;
};
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