Keep background image in P3D

When using the P3D render the loaded 2D image disappears but I will just want to overwrite parts of it with spheres. How to fix this?

PImage img;

void setup() {
  size(1500, 800,P3D);
  img = loadImage("String4.png");
  background(img);
}

void draw(){
directionalLight(79, 134, 247, 1, 0, -2);
fill(79,134,247);                               
noStroke();
pushMatrix();
int xp=round(width/4+random(width/2));int yp=round(height/4+random(height/2));
translate(xp,yp, 0);
sphere(50);
popMatrix();
}

Hi @Kylle,

Personally I never use the background() function to display an image fullscreen. But I don’t know why it clears the background at the first frame…

Using the image() function, works:

void setup() {
  size(1500, 800, P3D);
  img = loadImage("String4.png");
  image(img, 0, 0);
}

Hi,
Thanks for your reply!

But this is not the problem.
If I am not using sphere() and P3D, and instead for instance write a circle with the default render (in setup: size(1500, 800)), everything works well, i.e. the circles will be on top of the background image. You will still have the background image visible, except for the areas where the circles are.
When I am using the posted code the background image just disappears and turn gray.

Yes this the expected behavior, have you tried to use image instead of background?

This is what I have:

( Photo by Mo from Pexels)

Hi

It obvously works for you.
I am using Processing 4.0b.1, and there it does not work!?
Strange - a bug - different image files (quality/definition)?
I attach the file.
Kylle

PImage img;

void setup() {
size(1500, 800, P3D);
  img = loadImage("String4.png");
  image(img, 0, 0);
}

void draw(){
directionalLight(79, 134, 247, 1, 0, -2);
fill(79,134,247);                               
noStroke();
pushMatrix();
int xp=round(width/4+random(width/2));int yp=round(height/4+random(height/2));
translate(xp,yp, 0);
sphere(50);
popMatrix();
}
1 Like

Mmh it’s strange…

I was using Processing 3.5.4 so the bug was not reproducible anyway.

I installed Processing 4.0 beta 2 and your image and I have this:

Note that I am running on Linux…

Hi

I am running Processing on Windows.
Thanks for your efforts.
I solved the problem by masking a picture receving a “pure” ball image that I could paste on the background picture in numbers.
K

1 Like