Hello, Im trying to draw a texture(earth, sun, doesn’t really matter) on a 3d sphere, and I just can’t really figure how to do it, whenever I try to do it I get the following result:

I’ll post some code that explains a bit what I do:

This is my drawSphere method:

```
public void drawSphere(float radius) {
final float PI = 3.141592f;
float x, y, z, alpha, beta; // Storage for coordinates and angles
int gradation = 20;
for (alpha = 0.0f; alpha < Math.PI; alpha += PI / gradation) {
for (beta = 0.0f; beta < 2.01 * Math.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));
glTexCoord2f(x, y);
glVertex3f(x, y, z);
}
glEnd();
}
}
```

This is my rendering method from my “Star” class:

```
public void render() {
rotation += rotationSpeed;
glPushMatrix();
glRotatef(90, 1, 0, 0);
glRotatef(5, 0, 1, 0);
glRotatef(rotation, 0, 0, rotation);
glTranslatef(distance, distance, 0);
if (translate) {
glTranslatef(x, y, z);
}
glEnable(GL_TEXTURE_2D);
drawSphere(radius);
glPopMatrix();
}
```

“glEnable(GL_TEXTURE_2D);” is the method that shows the actual texture, and I tried other things like earth.bind, glTexCoord2f, and things like that, but nothing actually worked. How do I map the texture on the sphere? Im using lwjgl 3, so using all the glu options are not really available for me, I’ve heard its bad using those old methods, tho I can’t really understand why, but Im trying to stick with lwjgl 3.

I tried to not add too much irrelevant code so it will be easier, if more code is needed let me know. Thanks.