I am drawing a 3d sphere using GL_QUAD_STRIP primitive and it works except I don’t know how to set up the texture coordinates.
I have a certain number of division that divide my sphere into equal number of latitudes and longitudes. Hence, the sphere’s vertices are approximated using the divisions as follows
float x, y, z, dTheta=180/divisions, dLon=360/divisions, degToRad=3.14/180 ;
for(float lat =0 ; lat <=180 ; lat+=dTheta)
{
glBegin( GL_QUAD_STRIP ) ;
for(float lon = 0 ; lon <=360; lon+=dLon)
{
x = r*cosf(lat * degToRad) * sinf(lon * degToRad) ;
y = r*sinf(lat * degToRad) * sinf(lon * degToRad) ;
z = r*cosf(lon * degToRad) ;
glNormal3f( x, y, z) ;
glVertex3f( x, y, z ) ;
x = r*cosf((lat + dTheta) * degToRad) * sinf(lon * degToRad) ;
y = r*sinf((lat + dTheta) * degToRad) * sinf(lon * degToRad) ;
z = r*cosf( lon * degToRad ) ;
glNormal3f( x, y, z ) ;
glVertex3f( x, y, z ) ;
}
glEnd() ;
}
Okay the problem was that I was only drawing 2 vertices and
GL_QUAD_STRIPrequires 4. The following code now has both vertices set up properly and texture workingHope people who get stuck may find this useful.