# PGraphics weird transparency issue

**URL:** <https://discourse.processing.org/t/pgraphics-weird-transparency-issue/42015>\
**Category:** Coding Questions\
**Created:** [May 16, 2023, 10:20am UTC](https://discourse.processing.org/t/pgraphics-weird-transparency-issue/42015 "2023-05-16T10:20:40Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aryszin](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Aryszin](https://discourse.processing.org/u/Aryszin)\
**Post date:** [May 16, 2023, 10:20am UTC](https://discourse.processing.org/t/pgraphics-weird-transparency-issue/42015/1 "2023-05-16T10:20:40Z")

</div>

Its weird, i cant explain it, so ill get straight to the point;

this code makes the edge of the line look dark and weird. it uses a translucent background (not pixelated, thats fine);

```auto
PGraphics pg;

void setup() {
   size(960,540,P2D);
   pg = createGraphics(64,64);
}

void draw() {
   background(#FFFFFF);
   pg.beginDraw();
   pg.stroke(#FF0000);
   pg.strokeWeight(15);
   pg.line(0,0,64,64);
   pg.endDraw();
   image(pg,0,0,540,540);
}

```

but this code makes the edge look fine, it is like the default color; it doesnt use a tranclucent background.

```auto
PGraphics pg;

void setup() {
   size(960,540,P2D);
   pg = createGraphics(64,64);
}

void draw() {
   pg.beginDraw();
   pg.background(#FFFFFF);
   pg.stroke(#FF0000);
   pg.strokeWeight(15);
   pg.line(0,0,64,64);
   pg.endDraw();
   image(pg,0,0,540,540);
}

```

does anybody have an idea to fix this?

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [May 16, 2023, 11:54am UTC](https://discourse.processing.org/t/pgraphics-weird-transparency-issue/42015/2 "2023-05-16T11:54:02Z")

</div>

Hi @Aryszin,

would you provide a screen shot on what you see ? On my box there is absolutely no difference except the background gets completely filled white on the first example instead not filled partially on the second one ?

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![Aryszin](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Aryszin](https://discourse.processing.org/u/Aryszin)\
**Post date:** [May 16, 2023, 12:51pm UTC](https://discourse.processing.org/t/pgraphics-weird-transparency-issue/42015/3 "2023-05-16T12:51:34Z")

</div>

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/4/4/44039de11823f30e2f38c8ec3eb2e81ceb2a8f3c.png)  
yea sure here you go!

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [May 16, 2023, 3:12pm UTC](https://discourse.processing.org/t/pgraphics-weird-transparency-issue/42015/4 "2023-05-16T15:12:26Z")

</div>

Ahh! Ok! Now I see what you mean. The reason for that is, that in the first example you draw to pg over and over again without clearing the old content, which has somehow an additive behaviour …  
in the second example you clear the content, resp. fill white before drawing …

try this to see what’s ongoing …

```auto
PGraphics pg;

void setup() {
   size(960,540,P2D);
   pg = createGraphics(64,64);
}

void draw() {
   background(#FFFFFF);    
   pg.beginDraw();   
   if (mousePressed)
     pg.clear();
   pg.stroke(#FF0000);
   pg.strokeWeight(15);
   pg.line(0,0,64,64);
   pg.endDraw();
   image(pg,0,0,540,540);
}

```

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![Aryszin](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Aryszin](https://discourse.processing.org/u/Aryszin)\
**Post date:** [May 16, 2023, 4:10pm UTC](https://discourse.processing.org/t/pgraphics-weird-transparency-issue/42015/5 "2023-05-16T16:10:56Z")

</div>

thanks, but what do i do if it is for a drawing programm?

---

<div class="post-metadata">

**Author:** ![Aryszin](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Aryszin](https://discourse.processing.org/u/Aryszin)\
**Post date:** [May 16, 2023, 6:03pm UTC](https://discourse.processing.org/t/pgraphics-weird-transparency-issue/42015/6 "2023-05-16T18:03:52Z")

</div>

Oh! I just noticed that if you are rendering the pgraphics in P2D (createGraphics(64,64,P2D)) its doesnt matter if you clear the pg…

---

<div class="post-metadata">

**Author:** ![Aryszin](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Aryszin](https://discourse.processing.org/u/Aryszin)\
**Post date:** [May 16, 2023, 6:05pm UTC](https://discourse.processing.org/t/pgraphics-weird-transparency-issue/42015/7 "2023-05-16T18:05:18Z")

</div>

no wait, the clear command does not work???

---

<div class="post-metadata">

**Author:** ![Aryszin](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Aryszin](https://discourse.processing.org/u/Aryszin)\
**Post date:** [May 16, 2023, 6:06pm UTC](https://discourse.processing.org/t/pgraphics-weird-transparency-issue/42015/8 "2023-05-16T18:06:21Z")

</div>

no wait, it does??? im very confused im sorry…

---

<div class="post-metadata">

**Author:** ![Aryszin](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Aryszin](https://discourse.processing.org/u/Aryszin)\
**Post date:** [June 10, 2023, 9:37pm UTC](https://discourse.processing.org/t/pgraphics-weird-transparency-issue/42015/9 "2023-06-10T21:37:23Z")

</div>

You are technically right, but by using this code, it still wont work. I need to render the pg using P2D cause its way faster! hope you have an answer

```auto
PGraphics pg;

void setup() {
   size(960,540,P2D);
   pg = createGraphics(64,64,P2D);
}

void draw() {
   background(#FFFFFF);    
   pg.beginDraw();   
   if (mousePressed)
     pg.clear();
   pg.stroke(#FF0000);
   pg.strokeWeight(15);
   pg.line(0,0,64,64);
   pg.endDraw();
   image(pg,0,0,540,540);
}

```

---

<div class="post-metadata">

**Author:** ![Joseph](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@Joseph](https://discourse.processing.org/u/Joseph)\
**Post date:** [June 13, 2023, 8:10pm UTC](https://discourse.processing.org/t/pgraphics-weird-transparency-issue/42015/10 "2023-06-13T20:10:42Z")

</div>

Hey @Aryszin do u need this

> [@Aryszin](#):
>
> ```auto
> pg.beginDraw();   
> if (mousePressed)
> pg.clear();
> pg.stroke(#FF0000);
> pg.strokeWeight(15);
> pg.line(0,0,64,64);
> pg.endDraw();
> 
> ```

to be in draw() because the fact it’s being called repeatedly is the source of the bug.

---

<div class="post-metadata">

**Author:** ![Aryszin](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Aryszin](https://discourse.processing.org/u/Aryszin)\
**Post date:** [July 6, 2023, 9:50pm UTC](https://discourse.processing.org/t/pgraphics-weird-transparency-issue/42015/11 "2023-07-06T21:50:36Z")

</div>

Yes and it isn’t the source of the bug. Using P2D is tho.
