PDA

View Full Version : Texture Mapping a Sphere



OGL_PGR
12-06-2006, 08:46 PM
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();

Flavious
12-07-2006, 05:13 PM
Give this a try

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

paulyg
12-10-2006, 08:16 AM
Or this:

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