I'd like to get some help with texturing a 3d sphere, Im using the following code to draw a sphere:
public static void testing() {
final float PI = 3.141592f;
float x, y, z, alpha, beta; // Storage for coordinates and angles
float radius = 60f;
int gradation = 20;
for (alpha = 0.0f; alpha < PI; alpha += PI / gradation) {
glBegin(GL_TRIANGLE_STRIP);
for (beta = 0.0f; beta < 2.01 * PI; beta += PI / gradation) {
x = (float) (radius * Math.cos(beta) * Math.sin(alpha));
y = (float) (radius * Math.sin(beta) * Math.sin(alpha));
z = (float) (radius * Math.cos(alpha));
glVertex3f(x, y, z);
x = (float) (radius * Math.cos(beta) * Math.sin(alpha + PI / gradation));
y = (float) (radius * Math.sin(beta) * Math.sin(alpha + PI / gradation));
z = (float) (radius * Math.cos(alpha + PI / gradation));
glVertex3f(x, y, z);
}
glEnd();
}
}
The 3d sphere works just as it should, but I just don't really understand how to draw the texture on to it, I used slick utils to load the texture etc, and I manage to texture the sphere, but not really the way I need it to, how do I match/map the texture to the model? do I need to use glTexCoord2f go each glVertex3f? how does that work exactly? And how does the glVertex3f really works? Thanks.