Jump to content
  • Advertisement
Sign in to follow this  
AuC

Multitexturing 'Rotation'

This topic is 4838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.
	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;
 
                ...
}


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

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!