Please Help: How to add texture

Hello,
I wanted to create a sphere with texture on it. So I tried to make the image wrap around the sphere, but when I run the code, only the rotating sphere shows. Is there something wrong with the code?

def setup():
    size(550,700,P3D)
    global img
    img = loadImage('uranus.jpg')

r = 0;
z = 200; 

def draw():
    global r
    global z
    
    background(0)
    stroke('#FFFFFF')
    strokeWeight(2)
    fill('#FF0000')
    translate(width/2, height/2, z)
    rotateY(r)
    beginShape()
    texture(img)
    textureWrap(REPEAT)
    noFill()
    
    
    pushMatrix()
    translate(0,0)
    sphere(100)
    lights()
    popMatrix()
*emphasized text*

Wheres your endShape() call to close the shape.

Hello, I just added it and it still only gives me the rotating sphere without the texture.

Are you sure you are translating to the right place?

Yes, so when I run the program, everything is according to plan except the texture doesn’t come

Just cooking atm and then have some shopping to do, will check in later.

Take at look at the Processing JAVA example (see last section) to give you a idea of how this is done in the JAVA version:

https://processing.org/tutorials/pshape/

There is a reference in the PShape tutorial to the P3D tutorial which is available in JAVA and Python:
https://py.processing.org/tutorials/p3d/

I did not find a Processing Python tutorial on PShapes.

Now adapt this to the Processing Python version.

Start simple and just texture the sphere first and add other code later.

This is a working Processing (JAVA) version:

PShape sph;
PImage img;

void setup() 
  {
  size(300, 300, P3D);
  img = loadImage("frog.png");
  sph = createShape(SPHERE, 100);
  sph.setTexture(img);
  shape(sph, width/2, height/2);
  noLoop();
  }

You will have to adapt this to Python; this is not difficult and I was able to do this in Python.

Reference to help with createShape() for Python:
https://py.processing.org/reference/createShape.html

The Processing JAVA and Python version had the same output:

image

The Processing resources are here:
https://processing.org/
And you can select Python from the menu along the top.

:)

3 Likes