# PGraphics P2D background in setup issue

**URL:** https://discourse.processing.org/t/pgraphics-p2d-background-in-setup-issue/8112
**Category:** Coding Questions
**Created:** [February 4, 2019, 6:05pm UTC](https://discourse.processing.org/t/pgraphics-p2d-background-in-setup-issue/8112 "2019-02-04T18:05:29Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![wqt](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/wqt/32/3546_2.png) [@wqt](https://discourse.processing.org/u/wqt)
#### Post date: [February 4, 2019, 6:05pm UTC](https://discourse.processing.org/t/pgraphics-p2d-background-in-setup-issue/8112/1 "2019-02-04T18:05:29Z")

</div>

Hi there.  
I am using a PGraphics as a mask, the PGraphics’s background is set in the setup section so that my mask is not erased every frame.  
Somehow that works fine with the default renderer, but not in P2D, there is no background.  
I could of course initialize it in draw() only the first time, but does anyone know if there is a cleaner way to fix this?

```auto
PGraphics pg;

void setup(){
  size(600, 400, P2D);
  pg = createGraphics(width, height, P2D); // works with the default renderer, not in P2D
  pg.beginDraw();
  pg.background(0); // black background not showing in P2D PGraphics
  pg.endDraw(); 
}

void draw(){
  pg.beginDraw();
  pg.fill(255);
  pg.ellipse(mouseX, mouseY, 50, 50);
  pg.endDraw();
  image(pg, 0, 0);
}

```

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [February 5, 2019, 12:28am UTC](https://discourse.processing.org/t/pgraphics-p2d-background-in-setup-issue/8112/2 "2019-02-05T00:28:39Z")

</div>

> [@wqt](#):
>
> but not in P2D, there is no background

I tested this and it works for me using either the default or P2D renderer. What do you mean with the line above?

Sort of guessing, but what if you tried this for P2D in `setup()`:

```java
  pg.beginDraw();
  pg.fill(0);
  pg.rect(0,0,width,height);
  pg.endDraw();

```

Kf

---

<div class="post-metadata">

### Author: ![wqt](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/wqt/32/3546_2.png) [@wqt](https://discourse.processing.org/u/wqt)
#### Post date: [February 5, 2019, 10:18am UTC](https://discourse.processing.org/t/pgraphics-p2d-background-in-setup-issue/8112/3 "2019-02-05T10:18:48Z")

</div>

> What do you mean with the line above?

What I mean is that instead of displaying a black background, it shows the default gray background, as if I had not set it up.  
Nice idea for a workaround, but it doesn’t get me a black background either, still gray. It is like everything I draw on P2D PGraphics in setup is ignored.

> I tested this and it works for me using either the default or P2D renderer.

Perhaps I should report this as a bug? Btw I have Processing 3.5.2

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [February 6, 2019, 8:04pm UTC](https://discourse.processing.org/t/pgraphics-p2d-background-in-setup-issue/8112/4 "2019-02-06T20:04:40Z")

</div>

> [@wqt](#):
>
> instead of displaying a black background, it shows the default gray background, as if I had not set it up.

In Processing 3.4 I am seeing a black background with your test skech, as expected. So yes, this sounds like something that might be reported as an issue here:

> **[Issues · processing/processing](https://github.com/processing/processing/issues)**
>
> Source code for the Processing Core and Development Environment (PDE) - Issues · processing/processing
