summaryrefslogtreecommitdiff
path: root/warper
diff options
context:
space:
mode:
authorTim Redfern <tim@getdrop.com>2018-02-02 01:47:51 +0000
committerTim Redfern <tim@getdrop.com>2018-02-02 01:47:51 +0000
commit7c50a03c5857310aa383b1ba89a18792c96724b1 (patch)
tree97727831c97af5c06b39064dfdba60d61f7c7ae3 /warper
parent2b6c19dd192b07fe5980f667e26015da51c3106d (diff)
lots
Diffstat (limited to 'warper')
-rw-r--r--warper/Makefile13
-rw-r--r--warper/addons.make1
-rw-r--r--warper/bin/data/ofxaddons_thumbnail.pngbin0 -> 15473 bytes
-rw-r--r--warper/bin/data/ofxaddons_thumbnail@2x.pngbin0 -> 52207 bytes
-rw-r--r--warper/bin/data/settings.json1
-rw-r--r--warper/bin/data/shaders/ofxWarp/ControlPoint.frag16
-rw-r--r--warper/bin/data/shaders/ofxWarp/ControlPoint.vert23
-rw-r--r--warper/bin/data/shaders/ofxWarp/WarpBilinear.frag57
-rw-r--r--warper/bin/data/shaders/ofxWarp/WarpBilinear.vert21
-rw-r--r--warper/bin/data/shaders/ofxWarp/WarpPerspective.frag38
-rw-r--r--warper/bin/data/shaders/ofxWarp/WarpPerspective.vert21
-rw-r--r--warper/bin/data/testcard.pngbin0 -> 29159 bytes
-rw-r--r--warper/config.make142
-rw-r--r--warper/obj/osx/Release/.compiler_flags1
-rw-r--r--warper/src/main.cpp14
-rw-r--r--warper/src/ofApp.cpp222
-rw-r--r--warper/src/ofApp.h34
17 files changed, 604 insertions, 0 deletions
diff --git a/warper/Makefile b/warper/Makefile
new file mode 100644
index 0000000..177e172
--- /dev/null
+++ b/warper/Makefile
@@ -0,0 +1,13 @@
+# Attempt to load a config.make file.
+# If none is found, project defaults in config.project.make will be used.
+ifneq ($(wildcard config.make),)
+ include config.make
+endif
+
+# make sure the the OF_ROOT location is defined
+ifndef OF_ROOT
+ OF_ROOT=$(realpath ../../..)
+endif
+
+# call the project makefile!
+include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
diff --git a/warper/addons.make b/warper/addons.make
new file mode 100644
index 0000000..b0e37b8
--- /dev/null
+++ b/warper/addons.make
@@ -0,0 +1 @@
+ofxWarp
diff --git a/warper/bin/data/ofxaddons_thumbnail.png b/warper/bin/data/ofxaddons_thumbnail.png
new file mode 100644
index 0000000..622a643
--- /dev/null
+++ b/warper/bin/data/ofxaddons_thumbnail.png
Binary files differ
diff --git a/warper/bin/data/ofxaddons_thumbnail@2x.png b/warper/bin/data/ofxaddons_thumbnail@2x.png
new file mode 100644
index 0000000..67547e2
--- /dev/null
+++ b/warper/bin/data/ofxaddons_thumbnail@2x.png
Binary files differ
diff --git a/warper/bin/data/settings.json b/warper/bin/data/settings.json
new file mode 100644
index 0000000..e996b05
--- /dev/null
+++ b/warper/bin/data/settings.json
@@ -0,0 +1 @@
+{"warps":[{"blend":{"edges":"0, 0, 0.5, 0.5","exponent":2.0,"gamma":"1, 1, 1","luminance":"0.5, 0.5, 0.5"},"brightness":1.0,"type":2,"warp":{"columns":2,"control points":["0.0890625, 0.0597222","0.331009, 0.166569","0.388825, 0.477371","0.148126, 0.571886"],"rows":2}},{"adaptive":true,"blend":{"edges":"0.5, 0, 0, 0.5","exponent":2.0,"gamma":"1, 1, 1","luminance":"0.5, 0.5, 0.5"},"brightness":1.0,"linear":false,"resolution":16,"type":1,"warp":{"columns":5,"control points":["0.48418, 0.12602","0.554367, 0.469092","0.573438, 0.0392361","0.671484, 0.480903","0.725861, 0.186838","0.757812, 0.497917","0.824219, 0.0482639","0.840234, 0.410764","0.980469, 0.0527778","0.929688, 0.459722"],"rows":2}},{"adaptive":true,"blend":{"edges":"0.5, 0.5, 0, 0.5","exponent":2.0,"gamma":"1, 1, 1","luminance":"0.5, 0.5, 0.5"},"brightness":1.0,"corners":["0.585389, 0.542979","0.930469, 0.458333","0.898438, 0.870833","0.561719, 0.919444"],"linear":false,"resolution":16,"type":3,"warp":{"columns":5,"control points":["0, 0","0.0630292, 0.500232","0, 1","0.259811, -0.0268803","0.343242, 0.536344","0.259619, 1.09856","0.500002, 0.00670155","0.577167, 0.598489","0.513955, 1.19234","0.732039, -0.136884","0.82365, 0.508819","0.781408, 1.15969","1, 0","1.08493, 0.500191","1, 1"],"rows":3}},{"adaptive":true,"blend":{"edges":"0, 0.5, 0.5, 0","exponent":2.0,"gamma":"1, 1, 1","luminance":"0.5, 0.5, 0.5"},"brightness":1.0,"corners":["0.0460633, 0.677925","0.504574, 0.58986","0.567969, 0.920833","0.0382813, 0.911111"],"linear":false,"resolution":16,"type":3,"warp":{"columns":2,"control points":["0, 0","0.0784798, 0.507221","0, 1","1, 0","1.03334, 0.507208","1, 1"],"rows":3}}]} \ No newline at end of file
diff --git a/warper/bin/data/shaders/ofxWarp/ControlPoint.frag b/warper/bin/data/shaders/ofxWarp/ControlPoint.frag
new file mode 100644
index 0000000..87ef7a3
--- /dev/null
+++ b/warper/bin/data/shaders/ofxWarp/ControlPoint.frag
@@ -0,0 +1,16 @@
+#version 150
+
+in vec2 vTexCoord;
+in vec4 vColor;
+
+out vec4 fragColor;
+
+void main(void)
+{
+ vec2 uv = vTexCoord * 2.0 - 1.0;
+ float d = dot(uv, uv);
+ float rim = smoothstep(0.7, 0.8, d);
+ rim += smoothstep(0.3, 0.4, d) - smoothstep(0.5, 0.6, d);
+ rim += smoothstep(0.1, 0.0, d);
+ fragColor = mix(vec4( 0.0, 0.0, 0.0, 0.25), vColor, rim);
+}
diff --git a/warper/bin/data/shaders/ofxWarp/ControlPoint.vert b/warper/bin/data/shaders/ofxWarp/ControlPoint.vert
new file mode 100644
index 0000000..8eccc63
--- /dev/null
+++ b/warper/bin/data/shaders/ofxWarp/ControlPoint.vert
@@ -0,0 +1,23 @@
+#version 150
+
+// OF default uniforms and attributes
+uniform mat4 modelViewProjectionMatrix;
+uniform vec4 globalColor;
+
+in vec4 position;
+in vec2 texcoord;
+in vec4 color;
+
+// App uniforms and attributes
+in vec4 iPositionScale;
+in vec4 iColor;
+
+out vec2 vTexCoord;
+out vec4 vColor;
+
+void main(void)
+{
+ vTexCoord = texcoord;
+ vColor = globalColor * iColor;
+ gl_Position = modelViewProjectionMatrix * vec4(position.xy * iPositionScale.z + iPositionScale.xy, position.zw);
+}
diff --git a/warper/bin/data/shaders/ofxWarp/WarpBilinear.frag b/warper/bin/data/shaders/ofxWarp/WarpBilinear.frag
new file mode 100644
index 0000000..14597bb
--- /dev/null
+++ b/warper/bin/data/shaders/ofxWarp/WarpBilinear.frag
@@ -0,0 +1,57 @@
+#version 150
+
+uniform sampler2D uTexture;
+uniform vec4 uExtends;
+uniform vec3 uLuminance;
+uniform vec3 uGamma;
+uniform vec4 uEdges;
+uniform vec4 uCorners;
+uniform float uExponent;
+uniform bool uEditing;
+
+in vec2 vTexCoord;
+in vec4 vColor;
+
+out vec4 fragColor;
+
+float map(in float value, in float inMin, in float inMax, in float outMin, in float outMax)
+{
+ return outMin + (outMax - outMin) * (value - inMin) / (inMax - inMin);
+}
+
+float grid(in vec2 uv, in vec2 size)
+{
+ vec2 coord = uv / size;
+ vec2 grid = abs(fract(coord - 0.5) - 0.5) / (2.0 * fwidth(coord));
+ float line = min(grid.x, grid.y);
+ return 1.0 - min(line, 1.0);
+}
+
+void main(void)
+{
+ vec4 texColor = texture(uTexture, vTexCoord);
+
+ vec2 mapCoord = vec2(map(vTexCoord.x, uCorners.x, uCorners.z, 0.0, 1.0), map(vTexCoord.y, uCorners.y, uCorners.w, 0.0, 1.0));
+
+ float a = 1.0;
+ if (uEdges.x > 0.0) a *= clamp(mapCoord.x / uEdges.x, 0.0, 1.0);
+ if (uEdges.y > 0.0) a *= clamp(mapCoord.y / uEdges.y, 0.0, 1.0);
+ if (uEdges.z > 0.0) a *= clamp((1.0 - mapCoord.x) / uEdges.z, 0.0, 1.0);
+ if (uEdges.w > 0.0) a *= clamp((1.0 - mapCoord.y) / uEdges.w, 0.0, 1.0);
+
+ const vec3 one = vec3(1.0);
+ vec3 blend = (a < 0.5) ? (uLuminance * pow(2.0 * a, uExponent)) : one - (one - uLuminance) * pow(2.0 * (1.0 - a), uExponent);
+
+ texColor.rgb *= pow(blend, one / uGamma);
+
+ if (uEditing)
+ {
+ float f = grid(mapCoord.xy * uExtends.xy, uExtends.zw);
+ vec4 gridColor = vec4(1.0f);
+ fragColor = mix(texColor * vColor, gridColor, f);
+ }
+ else
+ {
+ fragColor = texColor * vColor;
+ }
+}
diff --git a/warper/bin/data/shaders/ofxWarp/WarpBilinear.vert b/warper/bin/data/shaders/ofxWarp/WarpBilinear.vert
new file mode 100644
index 0000000..81e4fad
--- /dev/null
+++ b/warper/bin/data/shaders/ofxWarp/WarpBilinear.vert
@@ -0,0 +1,21 @@
+#version 150
+
+// OF default uniforms and attributes
+uniform mat4 modelViewProjectionMatrix;
+uniform vec4 globalColor;
+
+in vec4 position;
+in vec2 texcoord;
+in vec4 color;
+
+// App uniforms and attributes
+out vec2 vTexCoord;
+out vec4 vColor;
+
+void main(void)
+{
+ vTexCoord = texcoord;
+ vColor = globalColor;
+
+ gl_Position = modelViewProjectionMatrix * position;
+}
diff --git a/warper/bin/data/shaders/ofxWarp/WarpPerspective.frag b/warper/bin/data/shaders/ofxWarp/WarpPerspective.frag
new file mode 100644
index 0000000..82c1a0b
--- /dev/null
+++ b/warper/bin/data/shaders/ofxWarp/WarpPerspective.frag
@@ -0,0 +1,38 @@
+#version 150
+
+uniform sampler2D uTexture;
+uniform vec3 uLuminance;
+uniform vec3 uGamma;
+uniform vec4 uEdges;
+uniform vec4 uCorners;
+uniform float uExponent;
+
+in vec2 vTexCoord;
+in vec4 vColor;
+
+out vec4 fragColor;
+
+float map(in float value, in float inMin, in float inMax, in float outMin, in float outMax)
+{
+ return outMin + (outMax - outMin) * (value - inMin) / (inMax - inMin);
+}
+
+void main(void)
+{
+ vec4 texColor = texture(uTexture, vTexCoord);
+
+ vec2 mapCoord = vec2(map(vTexCoord.x, uCorners.x, uCorners.z, 0.0, 1.0), map(vTexCoord.y, uCorners.y, uCorners.w, 0.0, 1.0));
+
+ float a = 1.0;
+ if (uEdges.x > 0.0) a *= clamp(mapCoord.x / uEdges.x, 0.0, 1.0);
+ if (uEdges.y > 0.0) a *= clamp(mapCoord.y / uEdges.y, 0.0, 1.0);
+ if (uEdges.z > 0.0) a *= clamp((1.0 - mapCoord.x) / uEdges.z, 0.0, 1.0);
+ if (uEdges.w > 0.0) a *= clamp((1.0 - mapCoord.y) / uEdges.w, 0.0, 1.0);
+
+ const vec3 one = vec3(1.0);
+ vec3 blend = (a < 0.5) ? (uLuminance * pow(2.0 * a, uExponent)) : one - (one - uLuminance) * pow(2.0 * (1.0 - a), uExponent);
+
+ texColor.rgb *= pow(blend, one / uGamma);
+
+ fragColor = texColor * vColor;
+}
diff --git a/warper/bin/data/shaders/ofxWarp/WarpPerspective.vert b/warper/bin/data/shaders/ofxWarp/WarpPerspective.vert
new file mode 100644
index 0000000..81e4fad
--- /dev/null
+++ b/warper/bin/data/shaders/ofxWarp/WarpPerspective.vert
@@ -0,0 +1,21 @@
+#version 150
+
+// OF default uniforms and attributes
+uniform mat4 modelViewProjectionMatrix;
+uniform vec4 globalColor;
+
+in vec4 position;
+in vec2 texcoord;
+in vec4 color;
+
+// App uniforms and attributes
+out vec2 vTexCoord;
+out vec4 vColor;
+
+void main(void)
+{
+ vTexCoord = texcoord;
+ vColor = globalColor;
+
+ gl_Position = modelViewProjectionMatrix * position;
+}
diff --git a/warper/bin/data/testcard.png b/warper/bin/data/testcard.png
new file mode 100644
index 0000000..d15c568
--- /dev/null
+++ b/warper/bin/data/testcard.png
Binary files differ
diff --git a/warper/config.make b/warper/config.make
new file mode 100644
index 0000000..469c495
--- /dev/null
+++ b/warper/config.make
@@ -0,0 +1,142 @@
+################################################################################
+# CONFIGURE PROJECT MAKEFILE (optional)
+# This file is where we make project specific configurations.
+################################################################################
+
+################################################################################
+# OF ROOT
+# The location of your root openFrameworks installation
+# (default) OF_ROOT = ../../..
+################################################################################
+ OF_ROOT = ../../openFrameworks
+
+################################################################################
+# PROJECT ROOT
+# The location of the project - a starting place for searching for files
+# (default) PROJECT_ROOT = . (this directory)
+#
+################################################################################
+# PROJECT_ROOT = .
+
+################################################################################
+# PROJECT SPECIFIC CHECKS
+# This is a project defined section to create internal makefile flags to
+# conditionally enable or disable the addition of various features within
+# this makefile. For instance, if you want to make changes based on whether
+# GTK is installed, one might test that here and create a variable to check.
+################################################################################
+# None
+
+################################################################################
+# PROJECT EXTERNAL SOURCE PATHS
+# These are fully qualified paths that are not within the PROJECT_ROOT folder.
+# Like source folders in the PROJECT_ROOT, these paths are subject to
+# exlclusion via the PROJECT_EXLCUSIONS list.
+#
+# (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank)
+#
+# Note: Leave a leading space when adding list items with the += operator
+################################################################################
+# PROJECT_EXTERNAL_SOURCE_PATHS =
+
+################################################################################
+# PROJECT EXCLUSIONS
+# These makefiles assume that all folders in your current project directory
+# and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations
+# to look for source code. The any folders or files that match any of the
+# items in the PROJECT_EXCLUSIONS list below will be ignored.
+#
+# Each item in the PROJECT_EXCLUSIONS list will be treated as a complete
+# string unless teh user adds a wildcard (%) operator to match subdirectories.
+# GNU make only allows one wildcard for matching. The second wildcard (%) is
+# treated literally.
+#
+# (default) PROJECT_EXCLUSIONS = (blank)
+#
+# Will automatically exclude the following:
+#
+# $(PROJECT_ROOT)/bin%
+# $(PROJECT_ROOT)/obj%
+# $(PROJECT_ROOT)/%.xcodeproj
+#
+# Note: Leave a leading space when adding list items with the += operator
+################################################################################
+# PROJECT_EXCLUSIONS =
+
+################################################################################
+# PROJECT LINKER FLAGS
+# These flags will be sent to the linker when compiling the executable.
+#
+# (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs
+#
+# Note: Leave a leading space when adding list items with the += operator
+################################################################################
+
+# Currently, shared libraries that are needed are copied to the
+# $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to
+# add a runtime path to search for those shared libraries, since they aren't
+# incorporated directly into the final executable application binary.
+# TODO: should this be a default setting?
+# PROJECT_LDFLAGS=-Wl,-rpath=./libs
+
+################################################################################
+# PROJECT DEFINES
+# Create a space-delimited list of DEFINES. The list will be converted into
+# CFLAGS with the "-D" flag later in the makefile.
+#
+# (default) PROJECT_DEFINES = (blank)
+#
+# Note: Leave a leading space when adding list items with the += operator
+################################################################################
+# PROJECT_DEFINES =
+
+################################################################################
+# PROJECT CFLAGS
+# This is a list of fully qualified CFLAGS required when compiling for this
+# project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS
+# defined in your platform specific core configuration files. These flags are
+# presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below.
+#
+# (default) PROJECT_CFLAGS = (blank)
+#
+# Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in
+# your platform specific configuration file will be applied by default and
+# further flags here may not be needed.
+#
+# Note: Leave a leading space when adding list items with the += operator
+################################################################################
+# PROJECT_CFLAGS =
+
+################################################################################
+# PROJECT OPTIMIZATION CFLAGS
+# These are lists of CFLAGS that are target-specific. While any flags could
+# be conditionally added, they are usually limited to optimization flags.
+# These flags are added BEFORE the PROJECT_CFLAGS.
+#
+# PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets.
+#
+# (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank)
+#
+# PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets.
+#
+# (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank)
+#
+# Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the
+# PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration
+# file will be applied by default and further optimization flags here may not
+# be needed.
+#
+# Note: Leave a leading space when adding list items with the += operator
+################################################################################
+# PROJECT_OPTIMIZATION_CFLAGS_RELEASE =
+# PROJECT_OPTIMIZATION_CFLAGS_DEBUG =
+
+################################################################################
+# PROJECT COMPILERS
+# Custom compilers can be set for CC and CXX
+# (default) PROJECT_CXX = (blank)
+# (default) PROJECT_CC = (blank)
+# Note: Leave a leading space when adding list items with the += operator
+################################################################################
+# PROJECT_CXX =
+# PROJECT_CC =
diff --git a/warper/obj/osx/Release/.compiler_flags b/warper/obj/osx/Release/.compiler_flags
new file mode 100644
index 0000000..8ce5d95
--- /dev/null
+++ b/warper/obj/osx/Release/.compiler_flags
@@ -0,0 +1 @@
+-Os -mtune=native -DNDEBUG -stdlib=libc++ -Wall -fexceptions -fpascal-strings -mmacosx-version-min=10.9 -D__MACOSX_CORE__ -x objective-c++ -std=c++11 -I../../openFrameworks/libs/FreeImage/include -I../../openFrameworks/libs/boost/include -I../../openFrameworks/libs/boost/include/boost -I../../openFrameworks/libs/cairo/include -I../../openFrameworks/libs/cairo/include/cairo -I../../openFrameworks/libs/curl/include -I../../openFrameworks/libs/curl/include/curl -I../../openFrameworks/libs/fmodex/include -I../../openFrameworks/libs/freetype/include -I../../openFrameworks/libs/freetype/include/freetype2 -I../../openFrameworks/libs/freetype/include/freetype2/freetype -I../../openFrameworks/libs/freetype/include/freetype2/freetype/config -I../../openFrameworks/libs/freetype/include/freetype2/freetype/internal -I../../openFrameworks/libs/freetype/include/freetype2/freetype/internal/services -I../../openFrameworks/libs/glew/include -I../../openFrameworks/libs/glew/include/GL -I../../openFrameworks/libs/glfw/include -I../../openFrameworks/libs/glfw/include/GLFW -I../../openFrameworks/libs/glm/include -I../../openFrameworks/libs/glm/include/glm -I../../openFrameworks/libs/glm/include/glm/detail -I../../openFrameworks/libs/glm/include/glm/gtc -I../../openFrameworks/libs/glm/include/glm/gtx -I../../openFrameworks/libs/glm/include/glm/simd -I../../openFrameworks/libs/json/include -I../../openFrameworks/libs/kiss/include -I../../openFrameworks/libs/pugixml/include -I../../openFrameworks/libs/rtAudio/include -I../../openFrameworks/libs/tess2/include -I../../openFrameworks/libs/uriparser/include -I../../openFrameworks/libs/uriparser/include/uriparser -I../../openFrameworks/libs/utf8/include -I../../openFrameworks/libs/utf8/include/utf8 -I../../openFrameworks/libs/utf8cpp/include -I../../openFrameworks/libs/utf8cpp/include/utf8 -I../../openFrameworks/libs/openFrameworks -I../../openFrameworks/libs/openFrameworks/3d -I../../openFrameworks/libs/openFrameworks/app -I../../openFrameworks/libs/openFrameworks/communication -I../../openFrameworks/libs/openFrameworks/events -I../../openFrameworks/libs/openFrameworks/gl -I../../openFrameworks/libs/openFrameworks/graphics -I../../openFrameworks/libs/openFrameworks/math -I../../openFrameworks/libs/openFrameworks/sound -I../../openFrameworks/libs/openFrameworks/types -I../../openFrameworks/libs/openFrameworks/utils -I../../openFrameworks/libs/openFrameworks/video -I/work/workspace/raverony/warper/src -I/work/workspace/openFrameworks/addons/ofxWarp/src -I/work/workspace/openFrameworks/addons/ofxWarp/src/ofxWarp -stdlib=libc++ -mmacosx-version-min=10.9 -v -framework Accelerate -framework QTKit -framework AGL -framework ApplicationServices -framework AudioToolbox -framework CoreAudio -framework CoreFoundation -framework CoreServices -framework OpenGL -framework IOKit -framework Cocoa -framework CoreVideo -framework AVFoundation -framework CoreMedia -framework QuartzCore -framework Security -framework LDAP
diff --git a/warper/src/main.cpp b/warper/src/main.cpp
new file mode 100644
index 0000000..b562734
--- /dev/null
+++ b/warper/src/main.cpp
@@ -0,0 +1,14 @@
+#include "ofMain.h"
+#include "ofApp.h"
+
+//========================================================================
+int main()
+{
+ ofGLFWWindowSettings settings;
+ settings.setGLVersion(3, 2);
+ settings.width = 1280;
+ settings.height = 720;
+ ofCreateWindow(settings);
+
+ ofRunApp(new ofApp());
+}
diff --git a/warper/src/ofApp.cpp b/warper/src/ofApp.cpp
new file mode 100644
index 0000000..3caaa07
--- /dev/null
+++ b/warper/src/ofApp.cpp
@@ -0,0 +1,222 @@
+#include "ofApp.h"
+
+//--------------------------------------------------------------
+void ofApp::setup()
+{
+ ofSetLogLevel(OF_LOG_NOTICE);
+ ofDisableArbTex();
+ ofBackground(ofColor::black);
+
+ ofImage image;
+ image.setUseTexture(false);
+ if (!image.load("testcard.png"))
+ {
+ ofLogError("ofApp::setup") << "Could not load image!";
+ return;
+ }
+
+ this->texture.enableMipmap();
+ this->texture.loadData(image.getPixels());
+
+ // Load warp settings from file if one exists.
+ this->warpController.loadSettings("settings.json");
+ if (this->warpController.getWarps().empty())
+ {
+ // Otherwise create warps from scratch.
+ shared_ptr<ofxWarpBase> warp;
+
+ warp = this->warpController.buildWarp<ofxWarpPerspective>();
+ warp->setSize(this->texture.getWidth(), this->texture.getHeight());
+ warp->setEdges(glm::vec4(0.0f, 0.0f, 1.0f, 1.0f));
+
+ warp = this->warpController.buildWarp<ofxWarpBilinear>();
+ warp->setSize(this->texture.getWidth(), this->texture.getHeight());
+ warp->setEdges(glm::vec4(1.0f, 0.0f, 0.0f, 1.0f));
+
+ warp = this->warpController.buildWarp<ofxWarpPerspectiveBilinear>();
+ warp->setSize(this->texture.getWidth(), this->texture.getHeight());
+ warp->setEdges(glm::vec4(0.0f, 1.0f, 0.0f, 0.0f));
+
+ warp = this->warpController.buildWarp<ofxWarpPerspectiveBilinear>();
+ warp->setSize(this->texture.getWidth(), this->texture.getHeight());
+ warp->setEdges(glm::vec4(0.0f, 1.0f, 1.0f, 0.0f));
+ }
+
+ this->srcAreas.resize(this->warpController.getNumWarps());
+
+ // Start with full area mode.
+ this->areaMode = -1;
+ this->keyPressed('a');
+
+ this->useBeginEnd = false;
+}
+
+//--------------------------------------------------------------
+void ofApp::exit()
+{
+ this->warpController.saveSettings("settings.json");
+}
+
+//--------------------------------------------------------------
+void ofApp::update()
+{
+ ofSetWindowTitle(ofToString(ofGetFrameRate(), 2) + " FPS :: " + areaName + " :: " + (this->useBeginEnd ? "begin()/end()" : "draw()"));
+}
+
+//--------------------------------------------------------------
+void ofApp::draw()
+{
+ ofBackground(ofColor::black);
+
+ if (this->texture.isAllocated())
+ {
+ for (auto i = 0; i < this->warpController.getNumWarps(); ++i)
+ {
+ auto warp = this->warpController.getWarp(i);
+ if (this->useBeginEnd)
+ {
+ warp->begin();
+
+ auto bounds = warp->getBounds();
+ this->texture.drawSubsection(bounds.x, bounds.y, bounds.width, bounds.height, this->srcAreas[i].x, this->srcAreas[i].y, this->srcAreas[i].width, this->srcAreas[i].height);
+
+ warp->end();
+ }
+ else
+ {
+ warp->draw(this->texture, this->srcAreas[i]);
+ }
+ }
+ }
+
+ ostringstream oss;
+ oss << ofToString(ofGetFrameRate(), 2) << " fps" << endl;
+ oss << "[a]rea mode: " << areaName << endl;
+ oss << "[d]raw mode: " << (this->useBeginEnd ? "begin()/end()" : "draw()") << endl;
+ oss << "[w]arp edit: " << (this->warpController.getWarp(0)->isEditing() ? "on" : "off");
+ ofSetColor(ofColor::white);
+ ofDrawBitmapStringHighlight(oss.str(), 10, 20);
+}
+
+//--------------------------------------------------------------
+void ofApp::keyPressed(int key)
+{
+ if (key == 'f')
+ {
+ ofToggleFullscreen();
+ }
+ else if (key == 'a')
+ {
+ this->areaMode = (this->areaMode + 1) % 3;
+ if (this->areaMode == 0)
+ {
+ // Draw the full image for each warp.
+ auto area = ofRectangle(0, 0, this->texture.getWidth(), this->texture.getHeight());
+ for (auto i = 0; i < this->warpController.getNumWarps(); ++i)
+ {
+ this->srcAreas[i] = area;
+ }
+
+ this->areaName = "full";
+ }
+ else if (this->areaMode == 1)
+ {
+ // Draw a corner region of the image so that all warps make up the entire image.
+ for (auto i = 0; i < this->warpController.getNumWarps(); ++i)
+ {
+ static const auto overlap = 10.0f;
+ if (i == 0)
+ {
+ // Top-left.
+ this->srcAreas[i] = ofRectangle(0, 0, this->texture.getWidth() * 0.5f + overlap, this->texture.getHeight() * 0.5f + overlap);
+ }
+ else if (i == 1)
+ {
+ // Top-right.
+ this->srcAreas[i] = ofRectangle(this->texture.getWidth() * 0.5f - overlap, 0, this->texture.getWidth() * 0.5f + overlap, this->texture.getHeight() * 0.5f + overlap);
+ }
+ else if (i == 2)
+ {
+ // Bottom-right.
+ this->srcAreas[i] = ofRectangle(this->texture.getWidth() * 0.5f - overlap, this->texture.getHeight() * 0.5f - overlap, this->texture.getWidth() * 0.5f + overlap, this->texture.getHeight() * 0.5f + overlap);
+ }
+ else
+ {
+ // Bottom-left.
+ this->srcAreas[i] = ofRectangle(0, this->texture.getHeight() * 0.5f - overlap, this->texture.getWidth() * 0.5f + overlap, this->texture.getHeight() * 0.5f + overlap);
+ }
+ }
+
+ this->areaName = "corners";
+ }
+ else
+ {
+ // Draw a random region of the image for each warp.
+ auto x1 = ofRandom(0, this->texture.getWidth() - 150);
+ auto y1 = ofRandom(0, this->texture.getHeight() - 150);
+ auto x2 = ofRandom(x1 + 150, this->texture.getWidth());
+ auto y2 = ofRandom(y1 + 150, this->texture.getHeight());
+ auto area = ofRectangle(x1, y1, x2 - x1, y2 - y1);
+ for (auto i = 0; i < this->warpController.getNumWarps(); ++i)
+ {
+ this->srcAreas[i] = area;
+ }
+
+ this->areaName = "random";
+ }
+ }
+ else if (key == 'd')
+ {
+ this->useBeginEnd ^= 1;
+ }
+}
+
+//--------------------------------------------------------------
+void ofApp::keyReleased(int key){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseMoved(int x, int y){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseDragged(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mousePressed(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseReleased(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseEntered(int x, int y){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseExited(int x, int y){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::windowResized(int w, int h){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::gotMessage(ofMessage msg){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::dragEvent(ofDragInfo dragInfo){
+
+}
diff --git a/warper/src/ofApp.h b/warper/src/ofApp.h
new file mode 100644
index 0000000..0476101
--- /dev/null
+++ b/warper/src/ofApp.h
@@ -0,0 +1,34 @@
+#pragma once
+
+#include "ofMain.h"
+#include "ofxWarp.h"
+
+class ofApp
+ : public ofBaseApp
+{
+public:
+ void setup();
+ void exit();
+
+ 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 mouseEntered(int x, int y);
+ void mouseExited(int x, int y);
+ void windowResized(int w, int h);
+ void dragEvent(ofDragInfo dragInfo);
+ void gotMessage(ofMessage msg);
+
+ bool useBeginEnd;
+ ofxWarpController warpController;
+ ofTexture texture;
+ vector<ofRectangle> srcAreas;
+ int areaMode;
+ string areaName;
+};