Texture Mapping a Sphere

Hi !

I’m trying to map a sphere with earth texture, but the image is flipped in horizontal direction.

Please let me know where am I going wrong ?

Thanks !

Code:

  
glBindTexture(GL_TEXTURE_2D, Texture);
glBegin(GL_TRIANGLE_STRIP);

for(phi = -90.0f,ty=0.0f; phi <= 90.0f-StepSize,ty<=1.0f; phi+=StepSize,ty+=tyStep)
	{
		for(theta=-180.0f,tx=0.0f; theta <= 180.0f-StepSize,tx<=1.0f; theta+= StepSize,tx+=txStep)
		{
			
			TopLeft		= GetPoint(theta			* D2R, phi			* D2R);
			TopRight	= GetPoint((theta+StepSize) * D2R, phi			* D2R);
			BottomLeft	= GetPoint(theta			* D2R,(phi-StepSize)* D2R);
			BottomRight	= GetPoint((theta+StepSize) * D2R,(phi-StepSize)* D2R);
			
			glTexCoord2f( tx , ty ); // TL // 1
			glVertex3f( TopLeft.x ,		TopLeft.y ,		TopLeft.z ); // 1

			glTexCoord2f( tx+txStep , ty ); // TR // 2 
			glVertex3f( TopRight.x ,	TopRight.y ,	TopRight.z ); // 2

			glTexCoord2f( tx , ty-tyStep ); // BL // 3 
			glVertex3f( BottomLeft.x ,	BottomLeft.y ,	BottomLeft.z );// 3

			glTexCoord2f( tx+txStep , ty-tyStep ); // BR // 4
			glVertex3f( BottomRight.x , BottomRight.y , BottomRight.z ); // 4 
		}
	}

	glEnd();

Give this a try

http://local.wasp.uwa.edu.au/~pbourke/texture/spheremap/

Or this:

http://www.paulyg.f2s.com/ogl.htm