Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

problems with P3D and OPENGL

$
0
0
I'm attempting to read a segment of video from a file in the data directory, store individual frames in an array and display these frames in a picture viewer that mimics Itunes coverflow.  I've been able to load the array in a sequential fashion by reading and storing each frame as the sketch cycles through the draw() method.  In fact, a previous iteration is able to display the frames, offsetting them on the x axis by ten.  This iteration of the sketch doesn't want to display the images to the screen and I know it has something to do with how OPENGL or P3D renders the image to the screen.  
I've used some of the code in this sketch which does exactly what I want to do but with a sequence of frames from a sample of a movie. http://www.openprocessing.org/sketch/10451  

This should work with any sample video.  I've been using the infamous cat clip, and also another sample from a movie.  here's the code:

import processing.video.*;
int maxImages = 35;
int router = 1;
int r=1;
Movie movie;
int ii = 0;
int iii = 0;
PImage[] gifs = new PImage[maxImages];

//these are all of the variables we need to run PhotoView
int imgCount = 35;
//int router = 1;
float imgX[] = new float[imgCount];
float imgY = 0;
float imgZ[] = new float[imgCount];
float imgWidth;
float imgHeight;
float Distance;
 
void setup()
{
   frameRate(5);
 size(1280, 900,P3D);
 //size(900, 900,OPENGL);
 setupImages();
 movie = new Movie(this, "cat.mov");
 movie.loop();
 // imageMode(CENTER);
}

void setupImages() {
 println("we are in setupImages");
imageMode(CENTER);
  }

void calcImagePos(int i) {
  imgX[i] = map(i, 0,7, 0, width);
  
  Distance = dist(imgX[i], imgY, mouseX, mouseY);
  imgZ[i] = -Distance;
  imgWidth = 400;
  imgHeight = imgWidth ;
}

void displayImages(int i) {
  pushMatrix();
  translate(imgX[i], height/2, imgZ[i]);
  println(imgX[i]+" <--- imgX["+i+"]   imgZ[i] -----> "+imgZ[i]+"  i= "+i+" gifs[i]= "+gifs[i]);
  popMatrix();
}  
 
void draw() { 
   // background(0);
  if (router ==1){
   image(movie,100,100,height/5,width/5);
   }
 if (router == 2){
   movie.stop();
 for (int x = 4; x<maxImages-3;x++){
   println("should spread them right here "+ x); 
   image(gifs[x], x*5, 0, imgWidth/2, imgHeight/2);
 }
 router = 3;
 }
 println("router= "+ router);
 if (router == 3){
   println("setting up images");
   router = 4;
   println("router = "+router);
   background(0);  
  }
  if (router == 4){
    
  // background(0);
  for(int i = 3; i < maxImages-2; i++){
    calcImagePos(i);
    displayImages(i);
    image(gifs[i], 500,500, imgWidth/2, imgHeight/2);
  }
  }
}

void movieEvent(Movie m){
  m.read(); 
  if (ii > maxImages-3)
  {
     println("The movie has stopped.");
     router = 2;
     println("router (in movieEvent) = "+router);
    }
  ii=frameCount;
   println("FRAMECOUNT= "+frameCount);
   println("load gifs[]");
    gifs[ii]=m.get(30,30,m.width,m.height);
  // image(gifs[ii],0,0);
    r=ii;
    if (r>1){
    r = int (random(0,ii));
    println("THE VALUE OF R= "+ r);
    if (gifs[r] == null) 
    {
    //checks to see whether the value is null before attempting to print to screen
      println(r+ "<---index for gifs with the value for r = null");
    }
      else{
      println("should print to screen right here");
      image(gifs[r],0,300); //why isn't this being displayed on the screen?
      }

    }
}


Viewing all articles
Browse latest Browse all 1768

Trending Articles