summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gui/addons.make2
-rw-r--r--gui/src/chainImage.cpp23
-rw-r--r--gui/src/chainImage.h20
-rw-r--r--gui/src/main.cpp4
-rw-r--r--gui/src/ofApp.cpp10
-rw-r--r--gui/src/ofApp.h1
-rw-r--r--gui/src/ofxGpuLutBlend.cpp127
-rw-r--r--gui/src/ofxGpuLutBlend.h26
-rw-r--r--gui/src/threadedSystemDialogs.cpp29
-rw-r--r--gui/src/threadedSystemDialogs.h20
10 files changed, 252 insertions, 10 deletions
diff --git a/gui/addons.make b/gui/addons.make
index 49ff8bc..f722f82 100644
--- a/gui/addons.make
+++ b/gui/addons.make
@@ -5,4 +5,4 @@ ofxArtnet
ofxThreadedImageLoader
ofxSyphon
ofxEasing
-ofxGpuLut \ No newline at end of file
+#ofxGpuLut \ No newline at end of file
diff --git a/gui/src/chainImage.cpp b/gui/src/chainImage.cpp
index 369ab77..3c6680f 100644
--- a/gui/src/chainImage.cpp
+++ b/gui/src/chainImage.cpp
@@ -467,15 +467,16 @@ void chainImage::drawChain(float fadeIn,bool additive,float intensity,float zoom
glScalef(zoomFactor,zoomFactor,zoomFactor);
//ofSetColor(colour);
- /*
+
float gamma=1.0f; //(startGamma*transition)+(1.0f*(1.0f-transition));
float pedestal=0.0f;
- float clamp=1.0f-transition;
+ float clamp=1.0f; //-transition;
lut.load(makeLut(gamma,pedestal,clamp));
+ lut.setBlend(1.0f);
lut.begin();
- */
+ //setAlpha(1.0f);
draw(0,0,getWidth(),getHeight());
- //lut.end();
+ lut.end();
glPopMatrix();
@@ -488,13 +489,25 @@ void chainImage::drawChain(float fadeIn,bool additive,float intensity,float zoom
//ofEnableAlphaBlending();
glEnable(GL_BLEND);
- ofSetColor(255,255,255,255*min(1.0,transition/fadeIn)*intensity);
+ //ofSetColor(255,255,255,255*min(1.0,transition/fadeIn)*intensity);
+ //setting alpha here doesn't work with shader?
+ //possibly if you could set the alpha when drawing?
link->setAnchorPoint(link->getWidth()/2,link->getHeight()/2);
+ gamma=1.0f; //(startGamma*transition)+(1.0f*(1.0f-transition));
+ pedestal=0.0f;
+ clamp=1.0f; //-transition;
+ lut.load(makeLut(gamma,pedestal,clamp));
+ lut.setBlend(transition);
+ lut.begin();
+
//ofSetColor(link->colour);
+ //link->setAlpha(transition);
link->draw(0,0,link->getWidth(),link->getHeight());
+ lut.end();
+
glDisable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
diff --git a/gui/src/chainImage.h b/gui/src/chainImage.h
index 30ea55a..3763aab 100644
--- a/gui/src/chainImage.h
+++ b/gui/src/chainImage.h
@@ -3,7 +3,7 @@
#include "ofMain.h"
#include "ofxJSON.h"
#include "ofxEasing.h"
-#include "ofxGpuLut.h"
+#include "ofxGpuLutBlend.h"
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max(a,b) ((a) > (b) ? (a) : (b))
@@ -47,7 +47,7 @@ class chainImage : public ofImage{
filename=_filename;
if (ofImage::load(filename)){
makeThumbnail();
-
+ //setImageType(OF_IMAGE_COLOR_ALPHA);
//could there be a way to load without committing the texture
//setUseTexture(false);
setAnchorPoint(getWidth()/2,getHeight()/2);
@@ -59,6 +59,20 @@ class chainImage : public ofImage{
return false;
}
+ void setAlpha(uint8_t a){
+ if (isAllocated()){
+ ofPixelsRef pixels = getPixels();
+ //uint8_t *im=(uint8_t *)&getPixels();
+ for (int i=0;i<getWidth()*getHeight();i++){
+ pixels[i]|=a;
+ }
+ }
+ }
+
+ void setAlpha(float a){
+ setAlpha((uint8_t)(a*255.0f));
+ }
+
int updateOutput(float decayRatio);
ofVec3f getTransform();
float getScale();
@@ -111,7 +125,7 @@ class chainImage : public ofImage{
bool isLoaded;
ofShader shader;
- ofxGpuLut lut;
+ ofxGpuLutBlend lut;
//int totalframes,framecount;
diff --git a/gui/src/main.cpp b/gui/src/main.cpp
index a171351..85db18d 100644
--- a/gui/src/main.cpp
+++ b/gui/src/main.cpp
@@ -5,6 +5,9 @@
//========================================================================
int main(int argc, char *argv[]){
+
+
+
/*
ofSetupOpenGL(1600,200,OF_WINDOW); // <-------- setup the GL context
@@ -58,6 +61,7 @@ int main(int argc, char *argv[]){
guiWindow->setVerticalSync(false);
shared_ptr<ofApp> mainApp(new ofApp);
+ mainApp->arguments = vector<string>(argv, argv + argc);
//mainApp->setupGui();
ofAddListener(guiWindow->events().update,mainApp.get(),&ofApp::updateGui);
diff --git a/gui/src/ofApp.cpp b/gui/src/ofApp.cpp
index 89e92c8..059b498 100644
--- a/gui/src/ofApp.cpp
+++ b/gui/src/ofApp.cpp
@@ -59,6 +59,16 @@ void ofApp::setup(){
ofSetFrameRate(30); // if vertical sync is off, we can go a bit fast... this caps the framerate at 60fps.
+
+ if (arguments.size()>1){
+ vector<string> args;
+ for (int i=1;i<arguments.size();i++){
+ ofLog()<<"argument: "<<arguments[i];
+ args.push_back(arguments[i]);
+
+ }
+ sets[0].addfiles(args);
+ }
}
//--------------------------------------------------------------
diff --git a/gui/src/ofApp.h b/gui/src/ofApp.h
index 9744184..a7d1c06 100644
--- a/gui/src/ofApp.h
+++ b/gui/src/ofApp.h
@@ -6,7 +6,6 @@
#include "ofxMidi.h"
#include "ofxSyphon.h"
#include "chainImageSet.h"
-#include "ofxGpuLut.h"
diff --git a/gui/src/ofxGpuLutBlend.cpp b/gui/src/ofxGpuLutBlend.cpp
new file mode 100644
index 0000000..85a0811
--- /dev/null
+++ b/gui/src/ofxGpuLutBlend.cpp
@@ -0,0 +1,127 @@
+#include "ofxGpuLutBlend.h"
+
+ofxGpuLutBlend::ofxGpuLutBlend(){}
+ofxGpuLutBlend::~ofxGpuLutBlend(){}
+
+void ofxGpuLutBlend::load(ofTexture lutTexture){
+
+ if(ofIsGLProgrammableRenderer()){
+ vertexShader = "#version 150\n";
+ vertexShader += STRINGIFY(
+ uniform mat4 projectionMatrix;
+ uniform mat4 modelViewMatrix;
+ uniform mat4 modelViewProjectionMatrix;
+
+ in vec4 position;
+ in vec2 texcoord;
+
+ out vec2 texCoordVarying;
+
+ void main()
+ {
+ texCoordVarying = texcoord;
+ gl_Position = modelViewProjectionMatrix * position;
+ }
+ );
+
+ fragmentShader = "#version 150\n";
+ fragmentShader += STRINGIFY(
+ uniform sampler2DRect tex;
+ uniform sampler2DRect lut;
+ uniform float blend;
+
+ in vec2 texCoordVarying;
+
+ out vec4 fragColor;
+
+ // Texture coordinates
+ vec2 texcoord0 = texCoordVarying;
+
+ float size = 64.0;
+
+ void main( void )
+ {
+ vec3 rawColor = texture(tex, texcoord0).rgb;
+ //float rawAlpha = texture(tex, texcoord0).a;
+
+ if (rawAlpha <= 0.0) {
+ fragColor = vec4(rawColor, 0.0);
+ }
+ else {
+ vec3 originalColor = floor(texture(tex, texcoord0).rgb * vec3(size - 1.0));
+ vec2 blueIndex = vec2(mod(originalColor.b, sqrt(size)), floor(originalColor.b / sqrt(size)));
+ vec2 index = vec2((size * blueIndex.x + originalColor.r) + 0.5, (size * blueIndex.y + originalColor.g) + 0.5);
+ fragColor = vec4(texture(lut, index).rgb, blend);
+ }
+ }
+ );
+
+ lutShader.setupShaderFromSource(GL_VERTEX_SHADER, vertexShader);
+ lutShader.setupShaderFromSource(GL_FRAGMENT_SHADER, fragmentShader);
+ lutShader.bindDefaults();
+ lutShader.linkProgram();
+ }
+ else {
+ fragmentShader = "#version 120\n#extension GL_ARB_texture_rectangle : enable\n";
+ fragmentShader += STRINGIFY(
+ uniform sampler2DRect tex;
+ uniform sampler2DRect lut;
+ uniform float blend;
+
+ float size = 64.0;
+
+ void main( void )
+ {
+ vec3 rawColor = texture2DRect(tex, gl_TexCoord[0].st).rgb;
+ //float rawAlpha = texture2DRect(tex, gl_TexCoord[0].st).a;
+
+ if (blend <= 0.0) {
+ gl_FragColor = vec4(rawColor, 0.0);
+ }
+ else {
+ vec3 originalColor = floor(texture2DRect(tex, gl_TexCoord[0].st).rgb * vec3(size - 1.0));
+ vec2 blueIndex = vec2(mod(originalColor.b, sqrt(size)), floor(originalColor.b / sqrt(size)));
+ vec2 index = vec2((size * blueIndex.x + originalColor.r) + 0.5, (size * blueIndex.y + originalColor.g) + 0.5);
+ gl_FragColor = vec4(texture2DRect(lut, index).rgb, blend);
+ }
+ }
+ );
+
+
+ lutShader.unload();
+ lutShader.setupShaderFromSource(GL_FRAGMENT_SHADER, fragmentShader);
+ lutShader.linkProgram();
+ }
+
+ lut.setTextureWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
+ lut.setTextureMinMagFilter(GL_NEAREST, GL_NEAREST);
+ if(!ofGetUsingArbTex()){
+ ofEnableArbTex();
+ lut = lutTexture;
+ ofDisableArbTex();
+ }else{
+ lut = lutTexture;
+ }
+ blendAmt=1.0f;
+}
+void ofxGpuLutBlend::setBlend(float amt){
+ blendAmt=amt;
+}
+void ofxGpuLutBlend::load(ofImage lutImage){
+ load(lutImage.getTexture());
+}
+
+void ofxGpuLutBlend::load(string path){
+ lutImage.load(path);
+ load(lutImage.getTexture());
+}
+
+void ofxGpuLutBlend::begin(){
+ lutShader.begin();
+ lutShader.setUniformTexture("lut", lut, 1);
+ lutShader.setUniform1f("blend", blendAmt);
+}
+
+void ofxGpuLutBlend::end(){
+ lutShader.end();
+} \ No newline at end of file
diff --git a/gui/src/ofxGpuLutBlend.h b/gui/src/ofxGpuLutBlend.h
new file mode 100644
index 0000000..d2f7d33
--- /dev/null
+++ b/gui/src/ofxGpuLutBlend.h
@@ -0,0 +1,26 @@
+#pragma once
+
+#include "ofMain.h"
+
+#define STRINGIFY(e) #e
+
+class ofxGpuLutBlend{
+
+private:
+ ofShader lutShader;
+ ofTexture lut;
+ string vertexShader;
+ string fragmentShader;
+ ofImage lutImage;
+ float blendAmt;
+public:
+ ofxGpuLutBlend();
+ ~ofxGpuLutBlend();
+
+ void load(ofTexture lutTexture);
+ void load(ofImage lutImage);
+ void load(string path);
+ void setBlend(float amt);
+ void begin();
+ void end();
+}; \ No newline at end of file
diff --git a/gui/src/threadedSystemDialogs.cpp b/gui/src/threadedSystemDialogs.cpp
new file mode 100644
index 0000000..597312f
--- /dev/null
+++ b/gui/src/threadedSystemDialogs.cpp
@@ -0,0 +1,29 @@
+
+#include "threadedSystemDialogs.h"
+#include "ofMain.h"
+
+void threadedSystemLoadDialog::load(std::string _caption,std::function<bool(std::string)> _callback){ //bool (*_callback)(std::string filename)){
+ caption=_caption;
+ load_callback=_callback;
+ startThread();
+}
+
+void threadedSystemLoadDialog::threadedFunction() {
+ setThreadName("threadedSystemLoadDialog " + ofToString(thread.get_id()));
+ ofFileDialogResult openFileResult= ofSystemLoadDialog(caption);
+
+ //Check if the user opened a file
+ if (openFileResult.bSuccess){
+
+
+ bool success=load_callback(openFileResult.fileName);
+
+ ofLogVerbose("Load %s %s\n",
+ openFileResult.filePath.c_str(),
+ success?"succeeded":"failed");
+
+
+ }else {
+ ofLogVerbose("User hit cancel");
+ }
+} \ No newline at end of file
diff --git a/gui/src/threadedSystemDialogs.h b/gui/src/threadedSystemDialogs.h
new file mode 100644
index 0000000..5a055b2
--- /dev/null
+++ b/gui/src/threadedSystemDialogs.h
@@ -0,0 +1,20 @@
+
+#pragma once
+
+#include "ofThread.h"
+#include "ofURLFileLoader.h"
+#include "ofTypes.h"
+
+
+class threadedSystemLoadDialog : public ofThread {
+ public:
+ threadedSystemLoadDialog(){};
+ ~threadedSystemLoadDialog(){};
+
+ void load(std::string _caption,std::function<bool(std::string)> _callback); //bool (*_callback)(std::string filename));
+
+ std::string caption;
+ std::function<bool(std::string)> load_callback;
+
+ virtual void threadedFunction();
+};