.setTexture() is working not texture()


I am having a problem with the texture() function. I would like to use it to apply a texture to a 3d object , for example a sphere. but for some reason it doesn't work while setTexture() woks fine. Is there something I am missing ?

here is my code :

float rotation;
PImage soltexture, fond;
PShape sol;

void setup() { 
  size(800, 600, P3D);
  camera(width/2.0, 200, 1500, width/2, 320, 0, 0, 1, 0);
  soltexture = loadImage("sol.jpg");
  fond = loadImage("fond.jpg");

  sol = createShape(SPHERE, 4000);
  sol.scale(1.85, 1.09, 1.15);
  //texture(soltexture);  // It doesn't work , I wonder why  ?
void draw() {
  // pour que l'image de fond ne recouvre pas les autres éléments
  image(fond, -504, -520);

  ambientLight(50, 50, 50);
  lightSpecular(255, 0, 114);
  spotLight(255, 0, 186, width/2, -3000, 0, width/2.0, 5000, -2000, 1, 60);

  translate(500, 5000, -2000);
  rotation = rotation + 0.006;

Thanks for your help!


  • Perhaps because you have texture() instead of sol.texture()?

    But also both methods are implemented in PShape with a primitive default implementation, but the real code, in PShapeOpenGL, only override setTexture(). Hence the difference. Not sure if that's an oversight (might worth a GitHub issue then) or intentionally (eg. wanting to deprecate texture()).

  • Thanks you for your replay PhiLho ! Well I actually tried sol.texture(xxxx); but it doesn't work either and I forgot to mention that it generates the following warning :

    texture() can only be called between beginShape() and endShape()

    which is weird because it is called between beginShape() and endShape(). I also have tried on an other computer on win7 and get the same result, so maybe i found a bug ? :/

    So while I am at it , I have got a second question :) : Maybe someone could explain me how to do a "REPEAT" of a texture using this method setTexure() ? Because with this method in my code the texture is wrapped and scaled around the object and it 's really ugly (you know, since my texture file is about 512x512).

Sign In or Register to comment.