We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I want to create an application which basically captures a webcam feed and applies a custom shader effect (GLSL) on it. Capture finds device, but only get black screen. On the other hand I can apply this shader effect to still image... Any help would be greatly appreciated..
processing
import processing.video.*;
Capture cam;
PImage still;
int w = 640;
int h = 480;
PShader shade;
void setup() {
size(w, h, P2D);
cam = new Capture(this, w, h);
cam.start();
still = createImage(w, h, RGB);
//still = loadImage("test.jpg");
shade = loadShader("sepia.glsl");
shade.set("image", still);
}
void draw() {
shader(shade);
if (cam.available()) {
cam.read();
}
still = cam.get();
image(still, 0, 0);
}
GLSL
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
#define PROCESSING_TEXTURE_SHADER
uniform sampler2D image;
varying vec4 vertTexCoord;
void main() {
vec4 texel = texture2D(image, vertTexCoord.st);
gl_FragColor = vec4(texel.x,texel.y,texel.z, 1.0);
gl_FragColor.r = dot(texel, vec3(.393, .769, .189));
gl_FragColor.g = dot(texel, vec3(.349, .686, .168));
gl_FragColor.b = dot(texel, vec3(.272, .534, .131));
}
Answers
I solved it in processing 1.5.1 (GLGraphics library) with "texSrc.putPixelsIntoTexture()".
"Everybody be cool, this is a processing robbery!"
You can temporarily stop and resume "security" webcam with mouse click. Fim grain and sepia shaders are applied to texSrc texture..
https://dl.dropboxusercontent.com/u/70391886/ROBBERY.zip
btw, is there any other way to copy one texture to another?
Utility function arrayCopy() is internally optimized and faster than a loop copy:
http://processing.org/reference/arrayCopy_.html
arrayCopy(textScr, textDest);