void Render()
{
static float fEarthRotation = 0.0f;
static float fSkyRotation = 0.0f;
...
if(m_bUseMultitexture)
{
glPushMatrix();
glTranslatef( 0.0f, 0.0f, -3.0f );
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
// Cloud texture
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, m_iCloudsTexture[0]);
glEnable(GL_TEXTURE_2D);
// Rotate cloud texture
glMatrixMode(GL_TEXTURE);
glTranslatef( -fSkyRotation / 100.0f, 0.0f, 0.0f );
glMatrixMode(GL_MODELVIEW);
// Earth texture
glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, m_iEarthTexture[0]);
glEnable(GL_TEXTURE_2D);
// Rotate earth texture
glMatrixMode(GL_TEXTURE);
glTranslatef(fEarthRotation / 100.0f, 0.0f, 0.0f);
glMatrixMode(GL_MODELVIEW);
// Draw the sphere
gluSphere(m_pEarthObj, 1.0f, 30, 30);
glPopMatrix();
}
...
fEarthRotation += 0.001f;
fSkyRotation += 0.001f;
...
}
Multitexturing 'Rotation'
Hello everyone,
Right now I'm preparing a game I want to write. In this game, which will be played on land and in space, people are positioned very close to the planet earth. I don't want it to be very detailed. So I though about two textures: one of the earths surface, and one of the sky.
This technique looks great! Right now I am using multipass multitexturing; the inner sphere, which is rotating to the left, has the earth texture, and the second sphere, rotating right, has the sky texture.
Of course the performance of multipass multexteturing isn't that great, so I wanted to implement normal multitexturing. However, I can't get both textures rotate in the opposite directions this way. My current approach is to translate the texture matrix, and then put the texture on the sphere.
This messy piece of code does work, but it doesn't work right. The textures are rotating in opposite directions, but the rotation starts slowly and is going faster and faster. So, how can I fix this? How can I rotate two textures on a sphere in opposite directions, with a constant speed?
And my second question: the sky texture I am using has black (no clouds) and white (clouds) shades. But when I place the texture on the earth, the white shades are transparent, and the black shaded are visible. How can I change this 'masking' color, so it masks the black texture?
~AuC
For your first problem remember that the texture matrix is a state, so each time you translate the matrix that translation is added to all previous translations. To avoid this just glLoadIdentity on the matrix before you translate (or better, after you've rendered, so that subsequent objects textures are not translated).
For the second problem, try a blending mode of GL_ONE, GL_ONE_MINUS_SRC_COLOR.
Enigma
For the second problem, try a blending mode of GL_ONE, GL_ONE_MINUS_SRC_COLOR.
Enigma
Quote:Original post by Enigma
For your first problem remember that the texture matrix is a state, so each time you translate the matrix that translation is added to all previous translations. To avoid this just glLoadIdentity on the matrix before you translate (or better, after you've rendered, so that subsequent objects textures are not translated).
Argh! Ofcourse -_- Stupid... :-)
Quote:Original post by Enigma
For the second problem, try a blending mode of GL_ONE, GL_ONE_MINUS_SRC_COLOR.
I'll try that! Thank you. :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement