Skip to content

Instantly share code, notes, and snippets.

@kylemcdonald
Last active December 23, 2015 02:09
Show Gist options
  • Save kylemcdonald/6565041 to your computer and use it in GitHub Desktop.
Save kylemcdonald/6565041 to your computer and use it in GitHub Desktop.
Experiments with automatically pushing/popping styles and matrices using scope.
#include "ofAppGlutWindow.h"
#include "ofMain.h"
#define stroke(r, g, b) StrokeClass StrokeObject##__LINE__(r, g, b)
class StrokeClass {
public:
StrokeClass(float r, float g, float b) {
ofPushStyle();
ofNoFill();
ofSetColor(r, g, b);
}
~StrokeClass() {
ofPopStyle();
}
};
#define translate(x, y) TranslateClass TranslateObject##__LINE__(x, y)
class TranslateClass {
public:
TranslateClass(float x, float y) {
ofPushMatrix();
ofTranslate(x, y);
}
~TranslateClass() {
ofPopMatrix();
}
};
class ofApp : public ofBaseApp {
public:
void draw() {
ofBackground(0);
{
stroke(255, 0, 0);
translate(10, 10);
ofRect(0, 0, 50, 50);
}
ofRect(20, 20, 50, 50);
}
};
int main() {
ofSetupOpenGL(200, 200, OF_WINDOW);
ofRunApp(ofPtr<ofBaseApp>(new ofApp()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment