Quest for setTexture

Hi. I want to make an hexagonal tile using the setTexture method of PShape, the problem is I want to run the following example

PImage img;
PShape globe;
	
void setup() {
  // Load an image
  img = loadImage("earth.jpg");
  globe = createShape(SPHERE, 50);
  // Automatically texture the shape with the image
  globe.setTexture(img);
}

And I get the message “IllegalArgumentException: createShape(SPHERE) is not supported in 2D” . I tried to set up to P3D using “size(640, 480, P3D)” but nothing is drawn. What am I doing wrong?

1 Like

You’re almost there …

https://processing.org/reference/shape_.html

1 Like

Nothing is drawn.
That’s wrong.

You created the shape, fine. (A 2D sphere? What’s that?)
Textured it, fine.
Now draw() it.

I’m sorry. You were right, nothing is being drawn. I forgot the draw method I used the shape method. Thanks both of you!

void setup() {
  size(400, 400, P3D);
  background(3,7,11);

  PImage img = loadImage("img.jpg");
  PShape globe = createShape(SPHERE, 100);
  globe.setTexture(img);
  globe.setStroke(color(0, 0));  

  shape(globe, width*0.5, height*0.5);
}
1 Like

I use it to learn the difference of putting “shape” in setup and “shape” in draw, if I write shape in setup, it blinks a lot (at least in my graphic card) if I use it in draw it is just drawn.

1 Like

In my example I had no reason to call it in draw(), but yes if you plan to animate/interact/ect, then move it into draw(). I was just looking to explicitly show you that you need to call the shape() function in order to draw the shape.

1 Like