Hi,

I'm an OpenGL noob, and I'm trying to put a texture on an ellipsoid (a disformed sphere).

The first difficulty was how to create an ellipsoid, but I found an almost similar function on the internet, which I have modified into this:

Code:
void drawEllipsoid(float a, float b, float c, int lats, int longs)
{
    int i, j;
    for(i = 0; i <= lats; i++)
    {
        float lat0 = M_PI * (-0.5f + (float) (i - 1) / lats);
        float z0  = sin(lat0);
        float zr0 = cos(lat0);
        
        float lat1 = M_PI * (-0.5f + (float) i / lats);
        float z1 = sin(lat1);
        float zr1 = cos(lat1);
        
        glBegin(GL_QUAD_STRIP);
        for(j = 0; j <= longs; j++)
        {
            float lng = 2 * M_PI * (float) (j - 1) / longs;
            float x = cos(lng);
            float y = sin(lng);
            
            glNormal3f(x * zr0, y * zr0, z0);
            glVertex3f(x * zr0 * a, y * zr0 * b, z0 * c);
            glNormal3f(x * zr1, y * zr1, z1);
            glVertex3f(x * zr1 * a, y * zr1 * b, z1 * c);
        }
        glEnd();
    }
}
This function creates a beautiful ellipsoid. Now I understand I have to use the glTexCoord2f function, but I can't figure out how, because honestly I don't really understand the way the above function draws the ellipsoid.

I have tried the following lines in the above function:
Code:
glTexCoord2f((i+1) / (float)lats, j / (float)longs);
glTexCoord2f(i / (float)lats, j / (float)longs);
This almost works, but the problem is that the texture gets very distorted...

Can somebody help me in the right direction? Or maybe someone knows a better way of creating an ellipsoid? (I am using GLUT, and it can only create perfect spheres)

Thanks in advance!