title: How do I wrap a texture around a sphere?
body: <p>I created a class with a method drawSphere to replace glutDrawSolidSphere. See code below.</p>
  
  <p>But I wonder, how do I wrap a texture around it without tiling? For example, if I want to draw a mouth, eyes and a nose on it, then I want it to have only one mouth, two eyes and one nose, and not 100 tiled all over the sphere.</p>
  
  <p>I'm using Jogl with some libraries.</p>
  
  <pre><code>class Shape {
  
      public void drawSphere(double radius, int slices, int stacks) {
          gl.glEnable(GL_TEXTURE_2D);
          head.bind(gl); //This method is a shorthand equivalent of gl.glBindTexture(texture.getTarget(), texture.getTextureObject());
          gl.glBegin(GL_QUADS);
          double stack = (2*PI)/stacks;
          double slice = (2*PI)/slices;
          for (double theta = 0; theta &lt; 2 * PI; theta += stack) {
              for (double phi = 0; phi &lt; 2 * PI; phi += slice) {
                  Vector p1 = getPoints(phi, theta, radius);
                  Vector p2 = getPoints(phi + slice, theta, radius);
                  Vector p3 = getPoints(phi + slice, theta + stack, radius);
                  Vector p4 = getPoints(phi, theta + stack, radius);
                  gl.glTexCoord2d(0, 0);
                  gl.glVertex3d(p1.x(), p1.y(), p1.z());
                  gl.glTexCoord2d(1, 0);
                  gl.glVertex3d(p2.x(), p2.y(), p2.z());
                  gl.glTexCoord2d(1, 1);
                  gl.glVertex3d(p3.x(), p3.y(), p3.z());
                  gl.glTexCoord2d(0, 1);
                  gl.glVertex3d(p4.x(), p4.y(), p4.z());
              }
          }
          gl.glEnd();
          gl.glDisable(GL_TEXTURE_2D);
      }
  
      Vector getPoints(double phi, double theta, double radius) {
          double x = radius * cos(theta) * sin(phi);
          double y = radius * sin(theta) * sin(phi);
          double z = radius * cos(phi);
          return new Vector(x, y, z);
      }
  }
  </code></pre>