I have a method for drawing a sphere:
static public void drawSphere(GL gl, double radius, int lats, int longs) {
/*
* This algorithm moves along the z-axis, for PI radians and then at
* each point rotates around the z-axis drawing a QUAD_STRIP.
*
* If you you start i at a non-zero value then you will see an open
* end along the z-axis. If you start j at a none zero-axis then you
* will see segements taken out.
*/
gl.glEnable(GL.GL_TEXTURE_GEN_S); // Enable Texture Coord Generation For S (NEW)
gl.glEnable(GL.GL_TEXTURE_GEN_T); // Enable Texture Coord Generation For T (NEW)
for ( int i = 0; i <= lats; i++) {
double lat0 = Math.PI * (-0.5 + (double) (i - 1) / lats);
double z0 = Math.sin(lat0) * radius;
double zr0 = Math.cos(lat0) * radius;
double lat1 = Math.PI * (-0.5 + (double) i / lats);
double z1 = Math.sin(lat1) * radius;
double zr1 = Math.cos(lat1) * radius;
gl.glBegin(GL.GL_QUAD_STRIP);
for ( int j = 0; j <= longs; j++) {
double lng = 2 * Math.PI * (double) (j - 1) / longs;
double x = Math.cos(lng) *radius;
double y = Math.sin(lng) *radius;
gl.glNormal3d(x * zr0, y * zr0, z0);
gl.glVertex3d(x * zr0, y * zr0, z0);
gl.glNormal3d(x * zr1, y * zr1, z1);
gl.glVertex3d(x * zr1, y * zr1, z1);
}
gl.glEnd();
}
gl.glDisable(GL.GL_TEXTURE_GEN_S);
gl. glDisable(GL.GL_TEXTURE_GEN_T);
}
I now want to modify this to allow for applying a texture around the globe. If I had split the sphere into QUADs, then I would probably have applied the texture as a percentage of the rotation, but I am not sure how I would do this with a quad strip?
I would like the texture to wrap around the object, like a map around a globe, rather than repeat.