createGraphics (width, height, renderer)

I’m compiling in my android phone with APDE.
APDE 0.5.1
Android 9 (Pie).

It seems you should explicitly set a renderer in size() if you are going to set a renderer in createGraphics.

It should be documented, since using createGraphics with a renderer is useful when your sketch mixes 2D and 3D graphics (chart with a title, game with score panel and so on).

This code works:

PGraphics l;
void setup(){
  float s=10.0;
  size(600,600);
  l=createGraphics(100,100);
  l.beginDraw();
  l.rect(s,s,s,s);
  l.endDraw();
  
}
void draw(){
  image(l,0,0);
}

This code does not work:

PGraphics l;
void setup(){
  float s=10.0;
  size(600,600);
/*this line changed: */
  l=createGraphics(100,100,P2D);
  l.beginDraw();
  l.rect(s,s,s,s);
  l.endDraw();
  
}
void draw(){
  image(l,0,0);
}

This code works:

PGraphics l;
void setup(){
  float s=10.0;
/* this line changed:*/
  size(600,600,P2D);
/*this line changed: */
  l=createGraphics(100,100,P2D); /* or P3D*/
  l.beginDraw();
  l.rect(s,s,s,s);
  l.endDraw();
  
}
void draw(){
  image(l,0,0);
}

It is createGraphics() / Reference / Processing.org

2 Likes

You’re right. Sorry!

1 Like