Skip to content

Instantly share code, notes, and snippets.

@chimanaco
Last active May 15, 2016 11:33
Show Gist options
  • Save chimanaco/4cbb5907f69166befbf4 to your computer and use it in GitHub Desktop.
Save chimanaco/4cbb5907f69166befbf4 to your computer and use it in GitHub Desktop.
oF to edit later
/* -------------------------------
DEBUG
------------------------------- */
/* prints Output sentence on screen */
cout << "DONE!: \n";
cout << "Position: " << position << "\n";
ofLog() << " event at " << f << endl;
/* -------------------------------
FRAME RATE
------------------------------- */
// Framerate on title
ofSetWindowTitle(ofToString(ofGetFrameRate(), 2));
// Draw string
http://qiita.com/satoruhiga/items/d4cf838a57e4043590ff
stringstream ss;
ss << "framerate: " << ofToString(ofGetFrameRate(), 0);
ofDrawBitmapString(ss.str(), 10, 20);
/* -------------------------------
CONST
------------------------------- */
/* internal */
const int PARTICLE_NUM = 15;
/* extarnal */
// .h
extern const int PARTICLE_NUM;
// .cpp
const int PARTICLE_NUM = 15;
/* -------------------------------
Erase first index in vector
------------------------------- */
vector<Particle *> particles;
particles.erase(particles.begin() + 0);
/* -------------------------------
Draw along circle
------------------------------- */
int radius = 500;
int circle_num = 10;
for(int i = 0; i < circle_num; i++) {
float angle = ofDegToRad(i * 360 / circle_num);
float x = cos(angle) * radius;
float y = sin(angle) * radius;
ofDrawCircle(x, y, 100, 100);
}
/* -------------------------------
Substruct String
------------------------------- */
string minutesString = ofToString(minutes);
if(minutes < 10) {
minutesString = "0" + minutesString.substr( 0, 1 );
}
/* -------------------------------
ofxGUI
------------------------------- */
// .h
#include "ofxGui.h"
ofxPanel gui;
ofxToggle isDisplay;
ofxButton button;
ofxFloatSlider speed;
ofxIntSlider total;
void speedChanged(float &speed);
// .cpp
void ofApp::setup(){
gui.setup("GUI");
// gui.setPosition(guiA.getPosition().x + guiA.getWidth() + GUI_MARGIN, guiA.getPosition().y);
gui.add(isDisplay.setup("isDisplay", true));
gui.add(speed.setup("speed", 100, 0, 255));
gui.add(total.setup("total", 0, 0, 5000));
// GUI load the last settings
gui.loadFromFile("settings.xml");
// addlistner
speed.addListener(this, &ofApp::speedChanged);
button.addListener(this, &ofApp::buttonPressed);
isDisplay.addListener(this, &ofApp::displayToggle);
}
void ofApp::draw(){
gui.draw();
}
//--------------------------------------------------------------
void ofApp::keyPressed (int key){
if(key == 's' || key == 'S') {
// GUI Save
gui.saveToFile("settings.xml");
}
}
// function
void ofApp::buttonPressed(){
// do something
}
void ofApp::speedChanged(float &speed){
// do something with speed
cout << "Speed: " << speed << "\n";
}
void ofApp::displayToggle(bool &toggle){
if(toggle) {
// if toggle on
} else {
// if toggle off
}
}
/* -------------------------------
ofxTween
------------------------------- */
// setup()
tweenA.setParameters(1, easing_linear, ofxTween::easeIn, 0, 0, 0, 0);
ofAddListener(tweenA.end_E, this, &ofApp::tweenCallback);
// update()
tweenA.update();
// draw() or update()
tweenA.getTarget(0)
// callback
void ofApp::tweenCallback(int &e){
int speed = 1000;
switch (e) {
case 1:
tweenA.setParameters(2, easing_expo, ofxTween::easeIn, 0, 100, speed, 0);
break;
case 2:
ofRemoveListener(tweenA.end_E, this, &ofApp::tweenCallback);
break;
default:
break;
}
}
/* -----------------------------------------------
Event Listner
----------------------------------------------- */
/* Event sender */
// eventNotify.h
void sendEvent(float currentTime);
ofEvent<float> isCompleted; // will send an event with a float
// eventNotify.cpp
void eventNotify::sendEvent(float currentTime){
ofNotifyEvent(isCompleted, currentTime, this);
}
/* Event receiver */
// ofApp.h
void startCompleted(float &f);
// ofApp.cpp
void ofApp::setup(){
ofAddListener(eventNotify.isCompleted, this, &CarScene::eventCompleted);
}
void ofApp::eventCompleted(float &f){
ofLog() << " event at " << f << endl;
ofRemoveListener(eventNotify.isCompleted, this, &ofApp::eventCompleted);
}
/* -------------------------------
Both side textured plane
------------------------------- */
void ofApp::setup(){
plane.set(width, height); ///dimensions for width and height in pixels
plane.setPosition(0, 0, 0); /// position in x y z
plane.setResolution(2, 2); /// this resolution (as columns and rows) is enough
// Enable textures on both sides
glEnable(GL_CULL_FACE);
}
void ofApp::draw(){
textureFront.getTexture().bind();
glFrontFace(GL_CW);
glCullFace(GL_FRONT);
plane.draw();
textureFront.getTexture().unbind();
textureBack.getTexture().bind();
glCullFace(GL_BACK);
plane.draw();
textureBack.getTexture().unbind();
}
// should disbale GL_CULL_FACE after use.
// Disable textures on both sides since it has set on TwoSideCard
glDisable(GL_CULL_FACE);
/* -------------------------------
Load Image
------------------------------- */
ofImage img;
string filename = "img.jpg";
// use old fashioned texture coordinates
ofDisableArbTex();
img.load(fileName);
// use default
ofEnableArbTex();
/* -------------------------------
GLSL Basic #120
------------------------------- */
// vs.vert
#version 120
void main() {
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
// fs.frag
#version 120
uniform sampler2D inputImageTexture;
void main() {
vec2 uv = gl_TexCoord[0].xy;
gl_FragColor = texture2D(inputImageTexture, uv );
}
/* -------------------------------
GLSL Basic #150
------------------------------- */
// vs.vert
#version 150
uniform sampler2D tex;
in vec4 colorVarying;
out vec4 fragColor;
void main (void) {
fragColor = texture(tex, gl_PointCoord) * colorVarying;
}
// fs.frag
#version 150
varying highp vec2 textureCoordinate;
uniform sampler2D inputImageTexture;
void main() {
gl_FragColor = texture2D(inputImageTexture, textureCoordinate);
}
/* -------------------------------
Boost for XCode
------------------------------- */
Build Setting -> Search Paths ->
Into Header Search Paths / Library Search Paths
/usr/local/Cellar/boost/1.58.0/include
/usr/local/Cellar/boost/1.58.0/lib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment