Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copying PGraphics to PImage using .get() or .copy() clears PGraphics object, if the renderer is P2D #681

Open
agrshch opened this issue Mar 2, 2023 · 3 comments
Labels
Help Wanted We have very little time and would like some help OpenGL Issues connected to P2D and P3D

Comments

@agrshch
Copy link

agrshch commented Mar 2, 2023

Description

An attempt of copying information from PGraphics to PImage using get() or copy() clears the PGraphics object if P2D renderer is used. It makes impossible many things, for example using PGraphics (or its copy) as a texture for the shader.

Expected Behavior

successful copying, like with default renderer

Current Behavior

both PGraphics and PImage are empty.

Steps to Reproduce

PGraphics img1;

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

img1 = createGraphics(200, 200, P2D);

img1.beginDraw();
img1.background(120);
img1.endDraw();

PImage img2 = img1.get(); // if comment out this line — grey rectangle appears
}

void draw() {
background(255);
image(img1, 100, 20);
}

Your Environment

  • Processing version: 4.2
  • Operating System and OS version: Mac OS 10.15.7
  • Other information:
@benfry benfry added OpenGL Issues connected to P2D and P3D Help Wanted We have very little time and would like some help labels Mar 3, 2023
@cacheflowe
Copy link

Tested & confirmed this bug report on Windows 11, with both P2D & P3D modes on the main app & PGraphics.

Interestingly, if you move the PGraphics drawing into the draw() loop, this bug doesn't happen, like so:

PGraphics img1;
PImage img2;

void setup() {
  size(300, 300, P2D);
  img1 = createGraphics(200, 200, P2D);
}

void draw() {
  img1.beginDraw();
  img1.background(120);
  img1.endDraw();
  
  if(img2 == null) {
    PImage img2 = img1.get();
  }
  
  background(255);
  image(img1, 100, 20);
}

@scudly
Copy link

scudly commented Apr 2, 2023

I found a hack that seems to work around it. Include a dummy beginDraw() / endDraw() in setup before doing anything. Anything in the first begin/end gets wiped out, but later ones, in either setup() or draw(), persist.

PGraphics pg;

void setup() {
  size( 300, 300, P2D );
  pg = createGraphics( 200, 200, P2D );
  
  // ---- include to fix ----
  pg.beginDraw();
  pg.endDraw();
  // ------------------------
  pg.beginDraw();
  pg.background( 255 );
  pg.endDraw();
}

void draw() {
  pg.beginDraw();
  pg.line( 10, 10, 190, 190 );
  pg.endDraw();
  
  image( pg, 10, 10 );
}

@mvaladas
Copy link
Contributor

mvaladas commented Jun 5, 2023

This looks related to what I investigated in #641.
I just submitted a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted We have very little time and would like some help OpenGL Issues connected to P2D and P3D
Projects
None yet
Development

No branches or pull requests

5 participants