We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Using video as texture (Read 553 times)
Using video as texture
May 31st, 2009, 7:42am
 
Is there any way to map a video as a texture in Processing 1.0? I have done it in previous versions but I can't seem to make it work now.

this is the code that I am trying to get working:


import processing.opengl.*;
import processing.video.*;

Capture camera;
int arraySize = 50;
PImage[] snapShot =new PImage[arraySize];
int index = 0;
boolean preview = true;

int slide1 = 0; // the slide number for the upper left quadrant. make three others
int slide2 = 0;
int slide3 = 0;
int slide4 = 0;

int slideNum = 0;
boolean justSnapped = false;
void setup()
{
 size(800, 600,OPENGL);


 camera = new Capture(this, 320, 240, 3);
 snapShot[index] = new PImage(320,240);

}



void draw()
{
 camera.read();
 


 //image(snapShot[slide], 0, 0);
 noStroke();
 //PImage a = snapShot[slide];

  if(preview==true){
   image(camera, 0, 0, width, height);
   //crosshairs
 }
 else{

 while(snapShot[slide1] == null) {
   slide1 = (slide1+1)%arraySize;
 }

 beginShape();
 texture(snapShot[slide1]);
 textureMode(NORMALIZED);
 vertex(0, 0, 0, 0);
 vertex(width/2, 0, .5, 0);
 vertex(width/2, height/2, .5, .5);
 vertex(0, height/2, 0, .5);
 endShape();

 while(snapShot[slide2] == null) { // do these need to be together?
   slide2 = (slide2+1)%arraySize;
 }

 beginShape();
 texture(snapShot[slide2]);
 textureMode(NORMALIZED);
 vertex(width/2, 0, .5, 0);
 vertex(width, 0, 1, 0);
 vertex(width, height/2, 1, .5);
 vertex(width/2, height/2, .5, .5);
 endShape();

 while(snapShot[slide3] == null) {
   slide3 = (slide3+1)%arraySize;
 }

 beginShape();
 texture(snapShot[slide3]);
 textureMode(NORMALIZED);
 vertex(width/2, height/2, .5, .5);
 vertex(width, height/2, 1, .5);
 vertex(width, height, 1, 1);
 vertex(width/2, height, .5, 1);
 endShape();

 while(snapShot[slide4] == null) {
   slide4 = (slide4+1)%arraySize;
 }

 beginShape();
 texture(snapShot[slide4]);
 textureMode(NORMALIZED);
 vertex(0, height/2, 0, .5);
 vertex(width/2, height/2, .5, .5);
 vertex(width/2, height, .5, 1);
 vertex(0, height, 0, 1);
 endShape();

 /*noStroke();
  PImage a = snapShot[slide];
  beginShape();
  texture(a);
  vertex(0, 0, 0, 0);
  vertex(width/2, 0, 1, 0);
  vertex(width/2, height/2, 1, 1);
  vertex(0, height/2, 0, 1);
  endShape();*/


 //slide=(slide+1)%arraySize;
 }
}
void keyPressed(){
 if (key == 's'){

   snapShot[index] = camera.get();
   println("captured at position " + index);
   index = (index+1)%(arraySize);

 }
 if(key == 'q'){
   if(slide1<arraySize-1 && slideNum>=0){
     slide1++;
     println("square 1 is at " + slide1);
   }
   else{
     slide1 = 0;
   }
 }
 if(key == 'w'){
   if(slide2<arraySize-1 && slideNum>=0){
     slide2++;
   }
   else{
     slide2 = 0;
   }
 }
 if(key == 'e'){
   if(slide3<arraySize-1 && slideNum>=0){
     slide3++;
   }
   else{
     slide3 = 0;
   }
 }
 if(key == 'r'){
   if(slide4<arraySize-1 && slideNum>=0){
     slide4++;
   }
   else{
     slide4 = 0;
   }
 }
 if(key == 'p'){
  if(preview==true){
   preview = false;
  }
  else if(preview==false){
   preview = true;
  }
 }
 
 
}
Page Index Toggle Pages: 1