Jump to content
  • Advertisement
Sign in to follow this  
X5-Programmer

Texture Terrain Question.

This topic is 5082 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

Hi, I have been reading about how to texture terrains by using the multitexturing, In this case its done by a title based grass texturing blended with an ditail texture, anyway my question is if I whant to have the grass texture over the whole terrain and title the ditail what changes do I have to make? my goal is to use the grass texture as a "all texture over the terrain" so I can make roads and stuffs on the map. I Hope you guys know what I mean :\. The render part is showed here. Grass texture = 1024*1024 Ditail texture = 256*256 g_DetailScale = 16 PATCHSIZE = 16 GL_TEXTURE0_ARB = Grass GL_TEXTURE1_ARB = Ditail
glActiveTextureARB(GL_TEXTURE0_ARB);
			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, g_Texture[TERRAIN_GRASS]);


			// Activate the second texture ID and bind the fog texture to it
			glActiveTextureARB(GL_TEXTURE1_ARB);
			glEnable(GL_TEXTURE_2D);
			
			// Here we turn on the COMBINE properties and increase our RGB
			// gamma for the detail texture.  2 seems to work just right.
			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
			glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2);
			
			// Bind the detail texture
			glBindTexture(GL_TEXTURE_2D, g_Texture[TERRAIN_DITAIL]);
		
			// Now we want to enter the texture matrix.  This will allow us
			// to change the tiling of the detail texture.
			glMatrixMode(GL_TEXTURE);

				// Reset the current matrix and apply our chosen scale value
				glLoadIdentity();
				glScalef((float)g_DetailScale, (float)g_DetailScale, 1);

			// Leave the texture matrix and set us back in the model view matrix
			glMatrixMode(GL_MODELVIEW);
			
			glPushMatrix();
			glCallList(terrain);
			glPopMatrix();

			glActiveTextureARB(GL_TEXTURE1_ARB);
			glDisable(GL_TEXTURE_2D);

			// Turn the first multitexture pass off
			glActiveTextureARB(GL_TEXTURE0_ARB);		
			glDisable(GL_TEXTURE_2D);

And here is the terrain part.

terrain = glGenLists(1);
glNewList(terrain, GL_COMPILE);

for (int y=0; y<PATCHSIZE; y++)
		{
			for(int x=0; x<(PATCHSIZE); x++)
			{
				
				glBegin(GL_TRIANGLES);
					NormalToOGL(&vertex[(y*(PATCHSIZE+1))+x], &vertex[(y*(PATCHSIZE+1))+(x+1)], &vertex[((y+1)*(PATCHSIZE+1))+x]);

					glMultiTexCoord2fARB(GL_TEXTURE0_ARB, (float)x/(float)PATCHSIZE*1, (1-((float)y/(float)PATCHSIZE))*1);
					glMultiTexCoord2fARB(GL_TEXTURE1_ARB, (float)x/(float)PATCHSIZE*1, (1-((float)y/(float)PATCHSIZE))*1);
					
					vertex[(y*(PATCHSIZE+1))+x].SendToOGL();
					
					glMultiTexCoord2fARB(GL_TEXTURE0_ARB, (float)(x+1)/(float)PATCHSIZE*1, (1-((float)y/(float)PATCHSIZE))*1);
					glMultiTexCoord2fARB(GL_TEXTURE1_ARB, (float)(x+1)/(float)PATCHSIZE*1, (1-((float)y/(float)PATCHSIZE))*1);

					vertex[(y*(PATCHSIZE+1))+(x+1)].SendToOGL();
	
					glMultiTexCoord2fARB(GL_TEXTURE0_ARB, (float)x/(float)PATCHSIZE*1, (1-((float)(y+1)/(float)PATCHSIZE))*1);
					glMultiTexCoord2fARB(GL_TEXTURE1_ARB, (float)x/(float)PATCHSIZE*1, (1-((float)(y+1)/(float)PATCHSIZE))*1);

					vertex[((y+1)*(PATCHSIZE+1))+x].SendToOGL();
					NormalToOGL(&vertex[((y+1)*(PATCHSIZE+1))+x], &vertex[(y*(PATCHSIZE+1))+(x+1)], &vertex[((y+1)*(PATCHSIZE+1))+(x+1)]);

					glMultiTexCoord2fARB(GL_TEXTURE0_ARB, (float)x/(float)PATCHSIZE*1, (1-((float)(y+1)/(float)PATCHSIZE))*1);
					glMultiTexCoord2fARB(GL_TEXTURE1_ARB, (float)x/(float)PATCHSIZE*1, (1-((float)(y+1)/(float)PATCHSIZE))*1);

					vertex[((y+1)*(PATCHSIZE+1))+x].SendToOGL();
					
					glMultiTexCoord2fARB(GL_TEXTURE0_ARB, (float)(x+1)/(float)PATCHSIZE*1, (1-((float)y/(float)PATCHSIZE))*1);
					glMultiTexCoord2fARB(GL_TEXTURE1_ARB, (float)(x+1)/(float)PATCHSIZE*1, (1-((float)y/(float)PATCHSIZE))*1);

					vertex[(y*(PATCHSIZE+1))+(x+1)].SendToOGL();

					glMultiTexCoord2fARB(GL_TEXTURE0_ARB, (float)(x+1)/(float)PATCHSIZE*1, (1-((float)(y+1)/(float)PATCHSIZE))*1);
					glMultiTexCoord2fARB(GL_TEXTURE1_ARB, (float)(x+1)/(float)PATCHSIZE*1, (1-((float)(y+1)/(float)PATCHSIZE))*1);
				
					vertex[((y+1)*(PATCHSIZE+1))+(x+1)].SendToOGL();
				glEnd();
			}
		}
glEndList();

I hope someone can fix this code to stretch the texture and explain some for me if you have time :). thx.

Share this post


Link to post
Share on other sites
Advertisement
Your current code does not stretch your grass texture across the terrain? It looks like that is what it is doing. Do you have a screenshot?

Share this post


Link to post
Share on other sites
Oh ok, I see.

When you compute the texture coordinates, instead of using

x / PatchSize

do

x / TerrainSize

Where TerrainSize is the entire width or length of the Terrain. Then you'll get the grass texture to stretch all the way across.

I'm sorry, I misunderstood what you were asking for before.

Share this post


Link to post
Share on other sites
Or like this

MAPSCALE = 16
PATCHSIZE = 16



#define SIZE (PATCHSIZE*MAPSCALE)*(PATCHSIZE*MAPSCALE)

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, (float)x/(float)SIZE*1, (1-((float)y/(float)SIZE))*1);



correct me :
Im not good att math ^^

Share this post


Link to post
Share on other sites
I'm not exactly sure what it is your asking for. Are you asking how to compute the texture coordinates themselves to stretch the grass over the entire terrain?

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!