Sign in to follow this  
X5-Programmer

Texture Terrain Question.

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
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
Guest Anonymous Poster
may be anybody knows, where can get good textures for land texturing? (tiles)

Share this post


Link to post
Share on other sites
I'm not sure about your code, but I think it should be:

#define SIZE (PATCHSIZE*MAPSCALE)

When you're calculating texture coordinates, you want to divide x and y by the width of the terrain.

Share this post


Link to post
Share on other sites
James Trotter:

yes I know I have try that, but then it looks like this.

http://www.frip.dk/socom/

there is the result.

if you need more info about the code what part you whant to see?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this