Skip to content

Instantly share code, notes, and snippets.

// This makes relative paths work in C++ in Xcode by changing directory to the Resources folder inside the .app bundle
// this way you can include your images in the copy phase of the project and don't have to rely on a data/ folder for distribution
#ifdef TARGET_OSX
ofDisableDataPath();
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
char path[PATH_MAX];
CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX);
CFRelease(resourcesURL);
@obviousjim
obviousjim / gist:6004420
Created July 15, 2013 23:27
GLSL RGB -> HSL
vec3 rgb2hsl( vec3 _input ){
float h = 0.0;
float s = 0.0;
float l = 0.0;
float r = _input.r;
float g = _input.g;
float b = _input.b;
float cMin = min( r, min( g, b ) );
float cMax = max( r, max( g, b ) );
@obviousjim
obviousjim / gist:6004436
Last active December 19, 2015 19:09
GLSL for reconstructing depth from HSL image
//Convert an RGB vec3 to an HSL vec3. We use the HUE value to encode depth, while SATURATION and BRIGHTNESS are always maxed out
vec3 rgb2hsl( vec3 _input ){
float h = 0.0;
float s = 0.0;
float l = 0.0;
float r = _input.r;
float g = _input.g;
float b = _input.b;
@obviousjim
obviousjim / gist:6060216
Created July 23, 2013 06:13
Using matrices to combine 4 kinect meshes
DRAW CODE:
cam.begin();
glPointSize(4);
ofSetColor(ofColor::green, 128);
West_SouthWest.checkPointMesh.drawVertices();
West_SouthWest.renderer.getMesh().drawVertices();
ofPushMatrix();
float depthValueFromSample( vec2 depthPos){
vec2 halfvec = vec2(.5,.5);
vec3 hsl = rgb2hsl( texture2DRect(texture, floor(depthPos) + halfvec ).xyz );
float depth = hsl.r;
if(hsl.b > .2){
return depth * ( maxDepth - minDepth ) + minDepth;
}
else {
return 0.0;
}
@obviousjim
obviousjim / gist:6192938
Created August 9, 2013 11:30
ofLight/ofShader/ofMaterial custom shader potential
cpp
ofLight myLight;
ofEnableLight();
myLight.begin(); --> registers the light with the ofGLRenderer
myShader.begin(); --> register the shader with ofGLRrenderer, which then passing all enabled lights to it as a uniform
myMaterial.begin(); --> registers
#include "ofMain.h"
#include "DKAppController.h"
#include "DKTimelineController.h"
#include "ofAppGLFWWindow.h"
//========================================================================
int main( ){
int guiPanelWidth = 454;
ofGLFWWindowSettings settings;
settings.width = 1920-guiPanelWidth;