Fixed Framingham and Frames examples in Video, added ImageMask in OpenGL/Shaders

This commit is contained in:
codeanticode
2012-08-16 17:52:27 +00:00
parent b00dedca58
commit bc1055792a
4 changed files with 54 additions and 20 deletions

View File

@@ -0,0 +1,25 @@
PImage srcImage;
PGraphics maskImage;
PShader maskShader;
void setup() {
size(200, 200, P2D);
srcImage = loadImage("milan_rubbish.jpg");
maskImage = createGraphics(srcImage.width, srcImage.height, P2D);
maskImage.noSmooth();
maskShader = loadShader("mask.glsl");
maskShader.set("maskSampler", maskImage);
}
void draw() {
maskImage.beginDraw();
maskImage.background(0);
maskImage.noStroke();
maskImage.fill(255, 0, 0);
maskImage.ellipse(mouseX, mouseY, 30, 30);
maskImage.endDraw();
shader(maskShader);
image(srcImage, 0, 0, width, height);
resetShader();
}

View File

@@ -0,0 +1,12 @@
uniform sampler2D textureSampler;
uniform sampler2D maskSampler;
uniform vec2 texcoordOffset;
varying vec4 vertColor;
varying vec4 vertTexcoord;
void main() {
vec4 texColor = texture2D(textureSampler, vertTexcoord.st).rgba;
vec4 maskColor = texture2D(maskSampler, vec2(vertTexcoord.s, 1.0 - vertTexcoord.t)).rgba;
gl_FragColor = mix(texColor, vec4(0, 0, 0, 0), 1.0 - maskColor.r);
}

View File

@@ -1,5 +1,3 @@
// Currently broken with the P2D renderer.
/**
* Framingham
* by Ben Fry.
@@ -42,14 +40,14 @@ void draw() {
if (video.available()) {
video.read();
video.loadPixels();
set(video.width*column, video.height*lastRow, video);
image(video, video.width*column, video.height*lastRow);
column++;
if (column == columnCount) {
loadPixels();
// Scoot everybody up one row
arraycopy(pixels, video.height*width, scoot, 0, scoot.length);
arraycopy(scoot, 0, pixels, 0, scoot.length);
arrayCopy(pixels, video.height*width, scoot, 0, scoot.length);
arrayCopy(scoot, 0, pixels, 0, scoot.length);
// Set the moved row to black
for (int i = scoot.length; i < width*height; i++) {

View File

@@ -3,8 +3,11 @@
* by Andres Colubri
*
* Moves through the video one frame at the time by using the
* arrow keys. It estimates the frame counts using the framerate
* of the movie file, so it might not be exact in some cases.
* arrow keys. Because it estimates the frame counts using the
* framerate of the movie file, and also, many movie codecs don't
* actually support jumping to arbitrary frames, don't expect
* accurate results in most cases.
*
*/
import processing.video.*;
@@ -16,28 +19,22 @@ PFont font;
void setup() {
size(320, 240, P2D);
background(0);
// Load and set the video to play. Setting the video
// in play mode is needed so at least one frame is read
// and we can get duration, size and other information from
// the video stream.
movie = new Movie(this, "station.mov");
movie.play();
newFrame = 0;
setFrame(newFrame);
noLoop();
font = loadFont("DejaVuSans-24.vlw");
textFont(font, 24);
}
void movieEvent(Movie movie) {
movie.read();
movie.read();
}
void draw() {
if (frameCount == 5) {
// Trick to force start at frame 0...
newFrame = 0;
setFrame(newFrame);
}
image(movie, 0, 0, width, height);
fill(240, 20, 30);
@@ -79,7 +76,9 @@ void setFrame(int n) {
movie.jump(where);
movie.pause();
movie.pause();
redraw();
}
int getLength() {