# Keep background image in P3D

**URL:** https://discourse.processing.org/t/keep-background-image-in-p3d/33224
**Category:** Coding Questions
**Created:** [November 1, 2021, 5:24pm UTC](https://discourse.processing.org/t/keep-background-image-in-p3d/33224 "2021-11-01T17:24:09Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Kylle](https://avatars.discourse-cdn.com/v4/letter/k/a88e4f/32.png) [@Kylle](https://discourse.processing.org/u/Kylle)
#### Post date: [November 1, 2021, 5:24pm UTC](https://discourse.processing.org/t/keep-background-image-in-p3d/33224/1 "2021-11-01T17:24:09Z")

</div>

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?

```auto
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();
}

```

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [November 1, 2021, 5:44pm UTC](https://discourse.processing.org/t/keep-background-image-in-p3d/33224/2 "2021-11-01T17:44:12Z")

</div>

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:

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

```

---

<div class="post-metadata">

### Author: ![Kylle](https://avatars.discourse-cdn.com/v4/letter/k/a88e4f/32.png) [@Kylle](https://discourse.processing.org/u/Kylle)
#### Post date: [November 1, 2021, 8:09pm UTC](https://discourse.processing.org/t/keep-background-image-in-p3d/33224/3 "2021-11-01T20:09:26Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [November 1, 2021, 8:31pm UTC](https://discourse.processing.org/t/keep-background-image-in-p3d/33224/4 "2021-11-01T20:31:47Z")

</div>

> [@Kylle](#):
>
> 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.

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

This is what I have:

- With `background`  

- With `image`  

( Photo by **[Mo](https://www.pexels.com/@mo-1268975?utm_content=attributionCopyText&utm_medium=referral&utm_source=pexels)** from **[Pexels](https://www.pexels.com/photo/render-of-textured-ball-9841281/?utm_content=attributionCopyText&utm_medium=referral&utm_source=pexels)**)

---

<div class="post-metadata">

### Author: ![Kylle](https://avatars.discourse-cdn.com/v4/letter/k/a88e4f/32.png) [@Kylle](https://discourse.processing.org/u/Kylle)
#### Post date: [November 2, 2021, 8:56am UTC](https://discourse.processing.org/t/keep-background-image-in-p3d/33224/5 "2021-11-02T08:56:44Z")

</div>

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

 ![String4](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/120d063d81896b6c0a874d3a250b9c14d588307b.jpeg)

```auto
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();
}

```

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [November 3, 2021, 8:05pm UTC](https://discourse.processing.org/t/keep-background-image-in-p3d/33224/6 "2021-11-03T20:05:05Z")

</div>

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:

 ![Screenshot from 2021-11-03 21-02-13](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e86241d50891071b803b49c484c6ec7918dd8d22.jpeg)

Note that I am running on Linux…

---

<div class="post-metadata">

### Author: ![Kylle](https://avatars.discourse-cdn.com/v4/letter/k/a88e4f/32.png) [@Kylle](https://discourse.processing.org/u/Kylle)
#### Post date: [November 4, 2021, 8:48am UTC](https://discourse.processing.org/t/keep-background-image-in-p3d/33224/7 "2021-11-04T08:48:21Z")

</div>

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
