Applying a texture to a sphere

edited November 2015 in Questions about Code

I'm attempting a simple tutorial that I found online on 3d shape texturing, but when I run the program, all I get is a black screen. This is my code:

PImage earth;
PShape globe;

void setup(){
  size(600,600,P3D);
  background(0);
  earth = loadImage("earth.jpg");
}

void draw(){
  translate(width/2,height/2);
  globe = createShape(SPHERE,50);
  globe.setTexture(earth);
}

Am I making a mistake, or is it just that my version of processing is outdated (I am running 2.1.2)? Help of any sort would be greatly appreciated. Thank you.

Answers

  • Answer ✓

    Ha! Fantastic failure! You're going to love this.

    Last chance to try to work it out yourself...

    Ok... here's the answer...

    When are you drawing your shape?

    PImage earth; 
    PShape globe;
    
    void setup() { 
      size(600, 600, P3D); 
      background(0); 
      String http = "http://"
      earth = loadImage( http + "previewcf.turbosquid.com/Preview/2014/08/01__15_41_30/Earth.JPG5a55ca7f-1d7c-41d7-b161-80501e00d095Larger.jpg");
      globe = createShape(SPHERE, 200); 
      globe.setTexture(earth);
      noStroke();
    }
    
    void draw() { 
      translate(width/2, height/2); 
      shape(globe);
    }
    
  • Ha!!! Thank you so much TfGuy44!!!

  • Does the size of the image that you're loading matter?

  • you have to test it....

    I think it should matter

Sign In or Register to comment.