PDA

View Full Version : Multitexturing a gluSphere



dvm
10-08-2004, 06:37 AM
Two posts in one day. Guess I'm keeping busy.
I want to make a sphere that represents the earth. I use gluShpere to do that. I set gluQuadricTexture(gluEarth, GL_TRUE), I binded my texture and it all worked fine. Now I'd like to use multitexturing to add another texture for clouds (my card supports it, I've run another working example of multitexturing) but I'm a little bit troubled.

I got the address of glActiveTextureARB and I tried to do it like this:


// in a LoadTextures function
if (g_bHasMultiTexture) {
g_CloudTexture = LoadTextureFile("textures/ev11643_cloud_combined_2048.bmp");

glBindTexture(GL_TEXTURE_2D, g_CloudTexture->texID);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, g_CloudTexture->width,
g_CloudTexture->height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE,
g_CloudTexture->data);

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, g_EarthTexture->texID);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, g_CloudTexture->texID);
}
// then my DrawEarth Function
void DrawEarth(float fX_, float fY_, float fZ_)
{
static GLUquadricObj *gluEarth;
glPushAttrib(GL_ALL_ATTRIB_BITS);
glActiveTextureARB(GL_TEXTURE0_ARB);
glTexGend(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGend(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGend(GL_R, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
glActiveTextureARB(GL_TEXTURE1_ARB);
glTexGend(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGend(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGend(GL_R, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
gluEarth = gluNewQuadric();
gluQuadricDrawStyle(gluEarth, GLU_FILL);
gluQuadricNormals(gluEarth, GLU_SMOOTH);
gluQuadricTexture(gluEarth, GL_FALSE);
gluQuadricOrientation(gluEarth, GLU_OUTSIDE);
glPushMatrix();
glTranslatef(fX_, fY_, fZ_);
glRotatef(g_fAngleX, 1.0, 0.0, 0.0);
glRotatef(g_fAngleY, 0.0, 1.0, 0.0);
glRotatef(g_fAngleZ, 0.0, 0.0, 1.0);
gluSphere(gluEarth, 12.742, 30, 30);
glPopMatrix();
glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);
glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);
glPopAttrib();
}The problem is that this thing completely messes up my textures. I also draw a moon, which is now textured as the earth! Also the earth texture doesn't look as good as with the tex coords from glu (I tried disabling the gluQuadricTexture when I turned on automatic texture coordinate generation). Does anyone know how to do this? Is there a tutorial out there?

vincoof
10-08-2004, 01:24 PM
glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);
glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);
Seems like you disable twice the texture generation commands for the same texture unit.