saveFrame function using background image and p3d

I am having trouble using saveFrame to record a sketch which uses p3d with a background image. When I use saveFrame without the background image everything is captured fine and shows the sketch but when I put the background image in it only records the background image. I am very new to coding and using processing so sorry if this is too simplistic. Any help would be great.

PImage bg;
int y;
int cols, rows; 
int scl = 20; 
int w = 2500;
  int h = 3000;
  float flying = 0;
  float[][] terrain; 

void setup() {
  size (800, 533, P3D);
  cols = w/scl; 
  rows = h/scl;
  terrain = new float[cols][rows];
  bg = loadImage("Glacier_Processing.jpg");

void draw() {
  flying -= 0.07;
  float yoff = flying;
  for (int y = 0; y < rows; y++) {
    float xoff = 0;
    for (int x = 0; x < cols; x++) {
      terrain[x][y] = map(noise(xoff,yoff), 0, 1, -250, 100); 
      xoff += 0.2;
    yoff += 0.2; 
  stroke(0, 100, 250, 75);
      translate(width/2, height/2);
      rotateX (PI/3.65);
  translate(-w/2, -h/2); 
  for (int y = 0; y < rows-1; y++) {
    for (int x = 0; x < cols; x++) {
      vertex(x*scl, y*scl, terrain[x][y]);
      vertex(x*scl, (y+1)*scl, terrain[x][y+1]);
      //rect(x*scl, y*scl, scl, scl); 


Did you try to place this line at the end of draw() please

Yeah unfortunately it does the same thing.

When running it displays everything its supposed to, its just the saved jpegs that appear as only the background image without the sketch itself.


It works with this line at the end of draw():


saveFrame() \ Language (API) \ Processing 3+


1 Like

Ok weird, it seems to still not be working for me. I am going to try sending it to a different computer and see if it just my computer. I haven’t updated my os in a long time so that could be it. Any chance you could send the lines of code where you placed saveFrame("output3/glacier_####.jpeg");

End of draw() loop.

See the reference for saveFrame().


1 Like