We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm working hard on my code and trying to add texture to my sphere. I'm not sure if I've written 'elegant' code. Probably not!
I have found the example of how to add texture which is:
PImage img;
PShape globe;
void setup() {
img = loadImage("earth.jpg");
globe = createShape(SPHERE, 50);
globe.setTexture(img);
}
Mine is certainly longer. Although I know some of it isn't relevant to the question, I'll post my whole code. The texture I'd like to use (for the sake of this) is scales. It's in the data folder and the sketch runs without errors - just a wireframe sphere though - no texture.
From what I've read and understand - the texture() must be between beginShape and endShape() and "before any calls to vertices".
Where you're using a sphere(); without explicit vertices, how can texture() be implemented?
Rather than posting separately, I have a couple more questions regarding the same code.
Many thanks in advance
// interactive sphere
PImage img;
int rotateX = 0, rotateY = 0;
int previousX, previousY;
float distanceX = 0.0, distanceY = 0.0;
void setup(){
size(1000, 1000, P3D);
img = loadImage("scales.jpg");
}
void draw(){
// background in draw not setup so drawn on loop and new sphere replaces old
background(0);
//lights();
// converts mouse x movement into rotation around the object - over-ridden by mouse pressed/dragged functions
camera(mouseX, height/2, (height/2) / tan(PI/3), mouseX, height/2, 0, 0, 1, 0);
// set centre of screen fro drawing sphere
translate(width/2, height/2, 0);
rotateX(rotateX + distanceY);
rotateY(rotateY + distanceX);
noFill();
stroke(255);
texture(img);
sphere (100);
}
void mousePressed()
{
previousX = mouseX;
previousY = mouseY;
}
void mouseDragged()
{
distanceX = radians(mouseX - previousX);
distanceY = radians(previousY - mouseY);
}
void mouseReleased()
{
rotateX += distanceY;
rotateY += distanceX;
distanceX = distanceY = 0.0;
}
Answers
AFaIK, texture() are for PShape & vertex() related stuff:
https://Processing.org/reference/texture_.html
https://Processing.org/reference/vertex_.html
However, sphere() got nothing to do w/ PShape, but it's a 3D primitive:
https://Processing.org/reference/sphere_.html
Although my experience w/ that is almost nil, I guess you may try out createShape() w/ SPHERE:
https://Processing.org/reference/createShape_.html