package com.haxademic.app.haxmapper.textures;

import processing.opengl.PShader;
import processing.video.Capture;

import com.haxademic.core.app.P;
import com.haxademic.core.debug.DebugUtil;
import com.haxademic.core.system.FileUtil;

public class TextureWebCam
extends BaseTexture {

	protected Capture _webCam;
	protected PShader _threshold;

	public TextureWebCam() {
		super();
		initWebCam();
		_threshold = P.p.loadShader( FileUtil.getHaxademicDataPath() + "shaders/filters/threshold.glsl");
	}
	
	void initWebCam() {
		String[] cameras = Capture.list();
		if (cameras.length == 0) {
			DebugUtil.printErr("Couldn't find a webcam");
			buildGraphics(100, 100);
		} else {
			_webCam = new Capture(P.p, cameras[6]);
			_webCam.start();
			buildGraphics(100, 100); 
		}
	}

	public void updateDraw() {
		if( _texture != null && _webCam != null && _webCam.available() == true ) { 
			if( _texture.width != _webCam.width && _webCam.width > 100 ) {
				buildGraphics( _webCam.width, _webCam.height ); 
			}
			
			_webCam.read(); 

			if( _texture != null ) {
				_texture.image( _webCam.get(), 0, 0 );
				_texture.filter( _threshold );
			}
		} else {
			_texture.clear();
		}
	}
}

@@ -44,76 +44,8 @@
 s;%0A%0A
-import processing.opengl.PShader;%0Aimport processing.video.Capture;%0A%0A
 impo
@@ -120,49 +120,40 @@
 il;%0A
+%0A
 import 
-com.haxademic.core.system.FileUtil
+processing.video.Capture
 ;%0A%0Ap
@@ -233,190 +233,116 @@
 am;%0A
-%09protected PShader _threshold;%0A%0A%09public TextureWebCam() %7B%0A%09%09super();%0A%09%09initWebCam();%0A%09%09_threshold = P.p.loadShader( FileUtil.getHaxademicDataPath() + %22shaders/filters/threshold.glsl%22
+%0A%09public TextureWebCam( int width, int height ) %7B%0A%09%09super();%0A%09%09buildGraphics( width, height );%0A%09%09initWebCam(
 );%0A%09
@@ -485,36 +485,8 @@
 %22);%0A
-%09%09%09buildGraphics(100, 100);%0A
 %09%09%7D 
@@ -559,37 +559,8 @@
 ();%0A
-%09%09%09buildGraphics(100, 100); %0A
 %09%09%7D%0A
@@ -672,187 +672,32 @@
 ) %7B 
-%0A%09%09%09if( _texture.width != _webCam.width && _webCam.width %3E 100 ) %7B%0A%09%09%09%09buildGraphics( _webCam.width, _webCam.height ); %0A%09%09%09%7D%0A%09%09%09%0A%09%09%09_webCam.read(); %0A%0A%09%09%09if( _texture != null ) %7B%0A%09
+%09%09%09%0A%09%09%09_webCam.read(); %0A
 %09%09%09_
@@ -734,16 +734,10 @@
 0, 0
+,
  
-);%0A%09%09%09%09
 _tex
@@ -745,49 +745,15 @@
 ure.
-filter( _threshold );%0A%09%09%09%7D%0A%09%09%7D else %7B%0A%09%09%09
+width, 
 _tex
@@ -761,14 +761,15 @@
 ure.
-clear(
+height 
 );%0A%09

Fix up webcam texture now that it works