Thanks for the reply. It is Processing 1.5 on Windows, Standard installation.
As I say, all works fine if I use the standard renderer. The images are loaded from the standard Data subfolder, not from the net. But they are large and with loadImage there is a pause when they are loaded (only when the frame with them appears for the first time, another confusion but a separate question), hence requestImage. See line 63.
And here is the code:
- //import processing.opengl.*;
- import java.io.*;
- String[] fileNames;
- // set a filter (which returns true if file's extension is .jpg)
- java.io.FilenameFilter txtFilter = new java.io.FilenameFilter() {
- boolean accept(File dir, String name) {
- return name.toLowerCase().endsWith(".jpg");
- }
- };
- PImage images[];
- int t = 0;
- float globalSpeed = 0.5;
- ImageFrame fr1, fr2;
- ImageFrame frames[];
- void setup() {
- size(screen.width, screen.height);
- frameRate(140);
- noCursor();
- // get the JPG images from /data subfolder within the sketch folder
- String folderPath = sketchPath + "\\data";
- fileNames = listFileNames(folderPath, txtFilter);
- //create an image bank
- imageBank("image_0", fileNames.length);
- fr1 = new ImageFrame(0, screen.width, globalSpeed, images[t]); // fill the first frame
- t = t+1; // move to the next image
- fr2 = new ImageFrame(-screen.width, screen.width, globalSpeed, images[t]); //fill the second frame
- }
- void draw() {
- if (t<images.length) {
- //draw a frame and check if it needs resetting
- if (fr1.drawFrame()) {
- t=t+1;
- if (t==images.length) {
- t = 0;
- }
- fr1.setFillerImage(images[t]);
- }
- //draw a frame and check if it needs resetting
- if (fr2.drawFrame()) {
- t=t+1;
- if (t==images.length) {
- t = 0;
- }
- fr2.setFillerImage(images[t]);
- }
- }
- }
- // this function creates an image bank by reading all JPG files in a folder
- void imageBank(String index, int filecount) {
- images = new PImage[filecount];
- for ( int i = 0; i< images.length; i++ ) {
- images[i] = loadImage(fileNames[i]); //REPLACE THIS WITH requestImage() to avoid stutter, does not work with OPENGL
- }
- }
- // This function returns all the files in a directory as an array of Strings
- String[] listFileNames(String dir, java.io.FilenameFilter extension) {
- File file = new File(dir);
- if (file.isDirectory()) {
- String names[] = file.list(extension);
- return names;
- }
- else {
- // If it's not a directory
- return null;
- }
- }
- ///////////// This is in a tab, not sure how to post...
- class ImageFrame {
- float xpos, fWidth, speed;
- PImage FillerImage;
- ImageFrame (float xpos, float fWidth, float speed, PImage FillerImage) {
- this.xpos = xpos;
- this.fWidth = fWidth;
- this.speed = speed;
- this.FillerImage = FillerImage;
- }
- boolean drawFrame() {
- image(this.FillerImage, xpos, 0, fWidth, height);
- xpos += speed;
- if (xpos > screen.width) {
- xpos = -screen.width;
- return true;
- }
- return false;
- }
- float getXpos() {
- return this.xpos;
- }
- void setXpos(float val) {
- this.xpos = val;
- }
- void setFillerImage(PImage val) {
- this.FillerImage = val;
- }
- }