Is it possible to draw main graphics on a PGraphics?

Is it possible to draw g on a PGraphics?
It should be done in P3D and it should be done without using loadPixels();

So something like this:

PGraphics pg;

void setup() {
  size(512, 512, P3D);  
  
  pg = createGraphics(256, 256, P3D);
  
}

void draw() {
  background(0);
  fill(255,255,0);
  circle(width/2, height/2, 256);
  
  pg.beginDraw();
  pg.image(g, 0, 0, pg.width, pg.height);
  pg.endDraw(); 
}

I tried different things with pre and post and endDraw but so far no luck.

1 Like

I try understand what you want but is not clear, are you expected somethinf like that ?

PGraphics pg;
PImage  img;

void setup() {
  size(512, 512, P3D);  
  pg = createGraphics(256, 256, P3D);
  img = createImage(pg.width, pg.height, RGB);
}

void draw() {
  background(0);
  fill(255,255,0);
  circle(width/2, height/2, 256);
  
  g.loadPixels(); // need to load to don't have have null pixels
  img.copy(g,0,0,pg.width,pg.height, 0,0,pg.width,pg.height);
  
  fill(255,0,0);
  circle(width/2, height/2, 256);
  
  image(img,0,0);
  /*
  pg.beginDraw();
  pg.image(img, 0, 0, pg.width, pg.height);
  pg.endDraw();
  */
  pg.loadPixels();
  println("pg",pg.pixels); // return null
}

1 Like

Can you explain why this is a requirement? This seems odd, since you want to access the pixels array of g ā€“ and that is what loadPixels is for.

You can try to skip this sometimes, but are explicitly warned against it in the reference:

Certain renderers may or may not seem to require loadPixels() or updatePixels() . However, the rule is that any time you want to manipulate the pixels[] array, you must have previously called loadPixels() , and after changes have been made, call updatePixels() . Even if the renderer may not seem to use this function in the current Processing release, this will always be subject to change.

Hi! What does no luck mean in this case?

I didnā€™t look at the source, but it could be that Processing automatically calls beginDraw and endDraw for the default g PGraphics at the begining and end of draw(). Maybe that means you canā€™t draw g onto something else because endDraw hasnā€™t been called yet?

Knowing why you want to do this may help suggest an alternative :slight_smile:

2 Likes

I made a renderer for the terminal:

I donā€™t want to use loadPixels on the main graphics cause it can be really slow depending on itā€™s size.
So what I do now is make a smaller graphics, then I draw g on that smaller graphics and load the pixels from that instead. I can only get this working in post which is not safe to draw, but it worksā€¦

Here is the repository if anyone is interested. If you made something cool then please post a image.

4 Likes

I really like this kind of hacks that push whatā€™s possible or reasonable :slight_smile:

:clap: :clap: :clap:

Wild.

Does it also work as system shell output when called from processing-java?

I will check later, if it doesnā€™t I can probably make it work.
That will make it also more friendly for PDE users that donā€™t have additional IDEā€™s installed.

O yeah the thing is Max / Linux only, this has to do that I put the terminal in character mode. And Iā€™m tired of making things cross platform.

That is totally fair ā€“ I am too. Although a ā€œTerminal Modeā€ for PDE would be pretty cool.

Some people wanted to work on the console:

Not sure if they started yet, and if they will, not sure if they will follow specification to make a descent terminal (supporting ANSI escapes, single character mode etc.)

2 Likes

It might be worth having a look at the JLine library for this. Should enable it to be fully cross-platform too.

1 Like

I wasnā€™t familiar with JLine. Looks like it is here:

1 Like

Yes, sorry, should have added a link! Itā€™s also the library used by the Java shell in the JDK.

I updated the project, more here: