We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello
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);
lights();
soltexture = loadImage("sol.jpg");
fond = loadImage("fond.jpg");
beginShape();
sol = createShape(SPHERE, 4000);
sphereDetail(64);
sol.scale(1.85, 1.09, 1.15);
//texture(soltexture); // It doesn't work , I wonder why ?
sol.setTexture(soltexture);
endShape(CLOSE);
}
void draw() {
background(0);
// pour que l'image de fond ne recouvre pas les autres éléments
hint(DISABLE_DEPTH_MASK);
scale(2);
image(fond, -504, -520);
hint(ENABLE_DEPTH_MASK);
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;
rotateX(rotation);
shape(sol);
}
Thanks for your help!
Comments
Perhaps because you have
texture()
instead ofsol.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).