# Accessing pixel array of PGraphics buffer is very slow if P3D render used

**URL:** <https://discourse.processing.org/t/accessing-pixel-array-of-pgraphics-buffer-is-very-slow-if-p3d-render-used/36034>\
**Category:** Coding Questions\
**Created:** [March 30, 2022, 4:36pm UTC](https://discourse.processing.org/t/accessing-pixel-array-of-pgraphics-buffer-is-very-slow-if-p3d-render-used/36034 "2022-03-30T16:36:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arcadeperfect](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@arcadeperfect](https://discourse.processing.org/u/arcadeperfect)\
**Post date:** [March 30, 2022, 4:36pm UTC](https://discourse.processing.org/t/accessing-pixel-array-of-pgraphics-buffer-is-very-slow-if-p3d-render-used/36034/1 "2022-03-30T16:36:40Z")

</div>

Hi

Trying to display PGraphics buffer as ascii characters.

The method is to render things to a PGraphics buffer, then iterate through the pixels manually and map them to ascii characters. It works fine when the PGraphics render is set to the default 2D one. However P3D (and P2D) make it very slow. I’m assuming it’s related to the GPU being involved.

Below code will run fine. If you change the ‘createGraphics’ line to use P3D it will be too slow. Is there any way around this?

Thanks!

```auto
int sw = 1000;
int sh = 800;

int bw = 70;
int bh = bw;

float r = 0;

PGraphics pg;

String chars = " ..o**OX@@";

float factor;

void setup() {

  size(1000, 1000, P3D);
  //pixelDensity(2);
  //pg = createGraphics(bw, bh, P3D);
  pg = createGraphics(bw, bh);
  factor = sw/bw;
}

void draw() {

  background(0);
  drawText();
  textSize(15);

  //image(pg, sw/2, sh/2);

  translate(0,0);

  for (int i = 0; i < bh*2; i ++) {
    for (int j = 0; j < bw*2; j++) {

      float p = brightness(pg.get(j, i));
      float q = p/255*9;

      //String chars = "..oo**OO@@";
      char l = chars.charAt(int(q));
      //print(factor);
      //text(i, j*factor, i*factor);
      text(l, j*factor, i*factor);
    }
  }
}

void drawText() {
  pg.beginDraw();
  pg.background(65);
  //pg.circle(0, 0, 10);
  pg.textSize(30);
  String time = "11:07";
  
  time = hour() + ":" + minute();
  
  float tw = pg.textWidth(time);
  float th = pg.textAscent();
  pg.translate(bw/2, bh/2);
  //pg.rotateY(radians(r));
  pg.rotate(radians(r));
  pg.text(time, -tw/2, th/4);

  r += 0.3;
  pg.endDraw();
  pg.filter(BLUR,1);
}

```

---

<div class="post-metadata">

**Author:** ![arcadeperfect](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@arcadeperfect](https://discourse.processing.org/u/arcadeperfect)\
**Post date:** [March 30, 2022, 4:50pm UTC](https://discourse.processing.org/t/accessing-pixel-array-of-pgraphics-buffer-is-very-slow-if-p3d-render-used/36034/2 "2022-03-30T16:50:35Z")

</div>

Never mind!

Creating an image from the PGraphics and accessing the pixels from there fixed it.

---

<div class="post-metadata">

**Author:** ![rapatski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rapatski/32/5164_2.png) [@rapatski](https://discourse.processing.org/u/rapatski)\
**Post date:** [April 1, 2022, 8:43am UTC](https://discourse.processing.org/t/accessing-pixel-array-of-pgraphics-buffer-is-very-slow-if-p3d-render-used/36034/3 "2022-04-01T08:43:02Z")

</div>

Still probably worth reporting as a bug?
