# PGraphics - read pixels as they are drawn

**URL:** <https://discourse.processing.org/t/pgraphics-read-pixels-as-they-are-drawn/21837>\
**Category:** Coding Questions\
**Created:** [June 13, 2020, 11:40am UTC](https://discourse.processing.org/t/pgraphics-read-pixels-as-they-are-drawn/21837 "2020-06-13T11:40:30Z")\
**Posts on this page:** 1\
**Showing post:** 19

<div class="post-metadata">

**Author:** ![mgood7123](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mgood7123](https://discourse.processing.org/u/mgood7123)\
**Post date:** [June 17, 2020, 10:28am UTC](https://discourse.processing.org/t/pgraphics-read-pixels-as-they-are-drawn/21837/19 "2020-06-17T10:28:03Z")

</div>

yea, i have already taken a bit of a look, as in [PGraphics framebuffer can be rendered in `noLoop` mode but cannot be rendered in `loop` mode](https://discourse.processing.org/t/pgraphics-framebuffer-can-be-rendered-in-noloop-mode-but-cannot-be-rendered-in-loop-mode/21912)

however my main goal is obtaining the pixels of a PGraphics Object, like what

```auto
graphicsObject.endDraw();
image(graphicsObject);

```

does

geometry and other stuff such as lights are not particularly important, only the pixels that get drawn, now i CAN do this in noLoop mode (looping = false) however this seems broken, and i do not know why

note that i get

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/274cd97caa83999824c3a23e3c43d5ecf6ef4f52.png)

if i have

```auto
void drawBox() {
  // draw a box onto the PGraphics object
  g2.background(0);
  int c = wrap(frameCount, 255);
  g2.fill(0, c, c);
  if (frameCount == 1) g2.lights();
  g2.noStroke();
  //g2.translate(width/2, height/2);
  //g2.rotateX(frameCount/100.0);
  //g2.rotateY(frameCount/200.0);
  g2.box(40);
}

void draw() {
  if (!looping) looping = true;
  
  background(0);

  drawBox();
  
  // render the PGraphic's FBO, note this fails in loop mode
  g2.imageFrameBuffer();
  
  int oldColor = getGraphics().fillColor;
  fill(255);
  textSize(16);
  text("frameCount = " + frameCount + ", FPS: " + frameRate, 10, 20);
  fill(oldColor);
}

```

which indicates that all geometry and stuff gets reset somewhere in endDraw

note that

> <https://github.com/mgood7123/Processing3_DirectR/blob/master/DirectR.pde#L17>

  
is used for `g2.imageFrameBuffer();`

in which if i do

```auto
  g2.beginDraw();
  drawBox();
  g2.endDraw();
  image(g2, 0, 0);

```

then lights gets reset in the next and subsequent draws

---

_[View the full topic](https://discourse.processing.org/t/pgraphics-read-pixels-as-they-are-drawn/21837)._
