PDA

View Full Version : ABOUT MAKE TEXTURE ON A SPHERE



ruixp
10-12-2001, 05:56 PM
I WANT MAKE A TEXTURE ON A SPHERE,EXAMPLES AS FOLLOW:

AUX_RGBImageRec* myimage;
unsigned char *image;
myimage=auxDIBImageLoad(_T("ground.bmp"));
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
image = (BYTE *)malloc(256*256*4);
gluScaleImage(GL_RGB,myimage->sizeX,myimage->sizeY,GL_UNSIGNED_BYTE,myimage->data,256,256,GL_UNSIGNED_BYTE,image);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);

glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_RE PLACE);
glTexImage2D(GL_TEXTURE_2D,0,3,256,256,0,GL_RGB,GL _UNSIGNED_BYTE,image);

//AUTOMATICAL TEXTURE MAPPING
glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);
glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);
glTexGenfv(GL_S,GL_EYE_PLANE,curEff);
glTexGenfv(GL_T,GL_EYE_PLANE,curEff);

//START TEXTURE MAPPING
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_2D);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);

GLUquadricObj *quadObj;
quadObj = gluNewQuadric();
gluQuadricDrawStyle(quadObj,GLU_FILL);
gluQuadricNormals(quadObj,GLU_SMOOTH);
gluSphere(quadObj,1.2,32,32);
//auxSolidSphere(1.0);

glPopMatrix();

glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_2D);

glDisable(GL_AUTO_NORMAL);
glDisable(GL_NORMALIZE);

I DON'T KNOW WHY THE TEXTURE CAN NOT ROTATE WITH THE SPHERE?

V--man
10-13-2001, 12:51 AM
>>>>I DON'T KNOW WHY THE TEXTURE CAN NOT ROTATE WITH THE SPHERE?>>>>>

NO NEED TO SHOUT! write in small letters please.
The sphere texgen functions does spherical mapping of texture coordinates, but don't confuse this with texturing a sphere.
The trick to texturing a sphere is to wrap the texture all around the sphere. Since you're using glu, I think that it has texture coordinates already, or maybe there is something to call to enable it.

V-man

silk
10-13-2001, 08:25 AM
In case you want to apply a single non-tiled texture to the sphere, the required instruction is:

gluQuadricTexture(quadratic, GL_TRUE);