Skip to content

Instantly share code, notes, and snippets.

@mattfelsen
Last active August 21, 2018 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattfelsen/d21f2dca8c1849cd249b7605bcdd51e0 to your computer and use it in GitHub Desktop.
Save mattfelsen/d21f2dca8c1849cd249b7605bcdd51e0 to your computer and use it in GitHub Desktop.
Bluecadet Views VideoView DrawMode for unwrapping a video in bands
diff --git a/apps/CentralStandard/src/Video/VideoView.cpp b/apps/CentralStandard/src/Video/VideoView.cpp
index c0c574e..750afab 100644
--- a/apps/CentralStandard/src/Video/VideoView.cpp
+++ b/apps/CentralStandard/src/Video/VideoView.cpp
@@ -13,7 +13,7 @@ using namespace bluecadet::utils;
namespace bluecadet {
namespace views {
-VideoView::VideoView() {
+VideoView::VideoView() : mDrawMode(DrawMode::Normal) {
setupShader();
}
@@ -73,6 +73,8 @@ void VideoView::setupShader() {
)).fragment(CI_GLSL(150,
uniform sampler2DRect uVideoTexture;
uniform vec2 uVideoSize;
+ uniform vec2 uCanvasSize;
+ uniform int uVideoDrawMode;
in vec4 vColor;
in vec2 vTexCoord0;
@@ -80,7 +82,22 @@ void VideoView::setupShader() {
void main() {
vec2 texCoord = vec2(vTexCoord0.x, 1.0 - vTexCoord0.y);
- oFragColor = vColor * texture(uVideoTexture, texCoord * uVideoSize);
+
+ if (uVideoDrawMode == 0) {
+ texCoord *= uVideoSize;
+ oFragColor = vColor * texture(uVideoTexture, texCoord);
+ }
+
+ else if (uVideoDrawMode == 1) {
+ texCoord *= uCanvasSize;
+ vec2 unmappedCoord = texCoord;
+
+ texCoord.x = mod(unmappedCoord.x, uVideoSize.x);
+ texCoord.y += (floor(unmappedCoord.x / uVideoSize.x) * uCanvasSize.y);
+
+ oFragColor = vColor * texture(uVideoTexture, texCoord);
+ }
+
}
)));
auto geom = geom::Rect(Rectf(vec2(0), vec2(1.0f)));
@@ -99,6 +116,7 @@ void VideoView::draw() {
mBatch->getGlslProg()->uniform("uVideoTexture", 0);
mBatch->getGlslProg()->uniform("uVideoSize", vec2(mPlayer->getWidth(), mPlayer->getHeight()));
mBatch->getGlslProg()->uniform("uCanvasSize", getSize());
+ mBatch->getGlslProg()->uniform("uVideoDrawMode", (int) mDrawMode);
mBatch->draw();
}
}
diff --git a/apps/CentralStandard/src/Video/VideoView.h b/apps/CentralStandard/src/Video/VideoView.h
index a27a135..221f89d 100644
--- a/apps/CentralStandard/src/Video/VideoView.h
+++ b/apps/CentralStandard/src/Video/VideoView.h
@@ -17,6 +17,11 @@ class VideoView : public bluecadet::views::BaseView {
public:
VideoView();
~VideoView();
+
+ enum class DrawMode {
+ Normal,
+ Unwrap
+ };
//! Loads the video. If key and path are empty, the existing key/path are used.
//! If a video for key already exists in the VideoManager, path can be left empty.
@@ -29,6 +34,9 @@ public:
void setAutoResize(const bool value) { mAutoResize = value; }
bool getAutoResize() const { return mAutoResize; }
+ void setDrawMode(const DrawMode mode) { mDrawMode = mode; }
+ DrawMode getDrawMode(const DrawMode mode) { return mDrawMode; }
+
const std::string & getKey() const { return mKey; }
protected:
@@ -37,6 +45,7 @@ protected:
void draw() override;
bool mAutoResize = true;
+ DrawMode mDrawMode;
ciWMFVideoPlayerRef mPlayer;
ci::gl::BatchRef mBatch;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment