Load image as background of sphere

edited January 2016 in How To...

I'm trying to make a sphere of size 30 with an image as the background. How do I do this? I'm using the directionalLight() method, so I think I need to incorporate the image somewhere in there. Anything helps!

Answers

  • just say background(imgBg);

    load imgBg in setup()

    nothing to do with your lights

    and now show your code...

  • edited January 2016

    I tried that, but I think there's an issue because the image I'm trying to load onto the sphere isn't the same size as the sphere...Here's my code.

    int y;
    PImage bg;
    PImage spherebg;
    
    void setup(){
      size(1024, 576, P3D);
      noStroke();
      fill(204);
      bg=loadImage("space.jpg");
      spherebg=loadImage("sun1.jpg");
    
      println(inventory);
      noLoop();
      fill(0);
      textAlign(CENTER);
    }
    
    void draw() {
      noStroke(); 
      background(bg);
      buildSphere();
    }
    
    void buildSphere(){
      float dirY = (mouseY / float(height) - 0.5) * 2;
      float dirX = (mouseX / float(width) - 0.5) * 2;
      directionalLight(99, 0, 66, -dirX, -dirY, -1); 
      translate(width/2 - 100, height/2, 0); 
      sphere(30); 
      background(spherebg);
      translate(200, 0, 0); 
      sphere(80); 
    }
    
  • edited January 2016

    this should be the first line in draw() to get the stars

    background(bg);
    

    this command can not give you the texture for the sphere though.

    You seem to mix this up a little: background stars and texture of the sphere.

    E.g. this line

    background(spherebg);
    

    makes no sense: background can not make the sphere texture.

    but you see how it is done in the other thread, ok...?

Sign In or Register to comment.