# Very weird stuff going on with colors and transparency with the P2D renderer

**URL:** <https://discourse.processing.org/t/very-weird-stuff-going-on-with-colors-and-transparency-with-the-p2d-renderer/40924>\
**Category:** Coding Questions\
**Created:** [February 14, 2023, 8:01pm UTC](https://discourse.processing.org/t/very-weird-stuff-going-on-with-colors-and-transparency-with-the-p2d-renderer/40924 "2023-02-14T20:01:24Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [February 24, 2023, 3:20pm UTC](https://discourse.processing.org/t/very-weird-stuff-going-on-with-colors-and-transparency-with-the-p2d-renderer/40924/9 "2023-02-24T15:20:16Z")

</div>

Hello @PianoMastR64,

When using PGraphics I have always had a setup frame first; I may have encountered this issue in the past and in the habit of doing this now.  
This will get around that first frame behavior.

This code has the PG setup frame and will toggle between PGraphics renderers (P2D and JAVA2D):

```auto
PGraphics pg;

boolean toggle;

void setup() 
  {
  size(800, 800, P2D);

  if (toggle)
    {
    pg = createGraphics(width, height, JAVA2D);
    println("PG P2D");
    println("Renderer: " + g.getClass().getName());
    println("Renderer: " + pg.getClass().getName());
    }
  else
    {
    pg = createGraphics(width, height, P2D);
    //println("PG JAVA2D");
    println("Renderer: " + g.getClass().getName());
    println("Renderer: " + pg.getClass().getName());
    }

  //Setup frame workaround
  pg.beginDraw();
  //pg.clear();
  pg.endDraw();

  pg.beginDraw();
  pg.noStroke();
  //pg.clear();
  pg.fill(255, 127);
  pg.rect(0, 0, 195, height);
  println(hex(pg.get(10, 10)));
  pg.endDraw();

  background(0);
  image(pg, 0, 0);
  }

void draw() 
  {
  pg.beginDraw();
  //pg.clear();

  pg.fill(255, 127);
  switch(frameCount) {
  case 1 :
    pg.rect(200, 0, 195, height);
    println(hex(pg.get(210, 10)));
    break;
  case 2 :
    pg.rect(400, 0, 195, height);
    println(hex(pg.get(410, 10)));
    break;
  case 3 :
    pg.rect(600, 0, 195, height);
    println(hex(pg.get(610, 10)));
    break;
    }

  pg.endDraw();

  background(0);
  image(pg, 0, 0);
  }

void keyPressed()
  {
  toggle = !toggle;
  frameCount = -1; // See https://discourse.processing.org/t/about-restarting/22557/3
  }

```

That still leaves the color mixing issues/behavior mentioned previously.

Reference:  
[https://discourse.processing.org/t/about-restarting/22557/3](https://discourse.processing.org/t/about-restarting/22557/3)

`:)`

---

_[View the full topic](https://discourse.processing.org/t/very-weird-stuff-going-on-with-colors-and-transparency-with-the-p2d-renderer/40924)._
