PGraphics Unexpected Behavior

Hi. I am doing the following process to use PGraphics with a texture and display it in a geometry. The same part of the code works in another sketch, but not isolated as you find here. Can someone explain to me why I am getting errors: texture() is not available with this renderer. vertex(x, y, u, v) is not available with this renderer.

PGraphics tempPG;
PImage img;

void setup() {
  size(225, 195, P3D);
  tempPG = createGraphics(225, 195);
  img = loadImage("img.png");

void draw() {

  tempPG.translate(width/2, height/2);
  tempPG.fill(255, 0, 0);


  tempPG.vertex(-106, 0, 0, 97);
  tempPG.vertex( -53, -92, 225/4, 0);
  tempPG.vertex(  53, -92, 225-(225/4), 0);
  tempPG.vertex( 106, 0, 225, 97);
  tempPG.vertex(  53, 92, 225-(225/4), 195);
  tempPG.vertex( -53, 92, 225/4, 195);

  image(tempPG, 0, 0);


  • Answer ✓

    Perhaps we should be more explicit in createGraphics() by specifying which renderer to instantiate:

    1. tempPG = createGraphics(width, height, JAVA2D);
    2. tempPG = createGraphics(width, height, P2D);
    3. tempPG = createGraphics(width, height, P3D);
  • GoToLoop is right. You are not specifying a renderer for your PGraphics, so then the default JAVA2D renderer is used (similar to not specifying a renderer in size()). When you look at the reference for texture() you will see that this method only works with the P2D and P3D renderers:

Sign In or Register to comment.