Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

schnegge

one texture for terrain

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

i wanna put one big bmp picture on my terrain, but the code doesnt work..why???
    
for (int z = 0; z < MAP_Z-1; z++)
{
        glBegin(GL_TRIANGLE_STRIP);
	for (int x = 0; x < MAP_X-1; x++)
	{
									    if (x==0 && z==0)
	    glTexCoord2f(0.0f, 0.0f);
							         glVertex3f(terrain[x][z][0], terrain[x][z][1], terrain[x][z][2]);

								
	     if (x==30 && z==0)
	     glTexCoord2f(1.0f, 0.0f);
							         glVertex3f(terrain[x+1][z][0], terrain[x+1][z][1], terrain[x+1][z][2]);

			
	     if (x==0 && z==30)
	     glTexCoord2f(0.0f, 1.0f);
	
             glVertex3f(terrain[x][z+1][0], terrain[x][z+1][1], terrain[x][z+1][2]);

	      if (x==30 && z==30)
	      glTexCoord2f(1.0f, 1.0f);
				
	      glVertex3f(terrain[x+1][z+1][0], terrain[x+1][z+1][1], terrain[x+1][z+1][2]);
	}
	glEnd();
}
   
if i texture each triangle it looks nice...if i wanna put one big texture over the hole terrain it looks really weird [edited by - schnegge on May 31, 2002 2:15:03 PM]

Share this post


Link to post
Share on other sites
Advertisement
Obviously it is going to look weird. Depending on the size of your terrain and the size of your texture, the texture may be streched across the terrain (leading to a loss of detail), or it is being streched in an odd proportion (i.e. not a square), so it may also be squished in one axis.

Share this post


Link to post
Share on other sites
maybe calculate tex coordinates for every poly. like doing a model. something like (MAPZ-1)/z except when z = 0, z==0 then texcoor = 0;
by the way, if you''re not using frustum culling or some other visibility check. use drawelements to render the terrain.

Share this post


Link to post
Share on other sites
i changed now the code from the nehe tut. i can now use one texture for the whole map. unfortunaltely it dosnt work right. i wanna texture this pic:

and it looks like this:



why??
here is the code:

    
float xTexture = 0.0f;
float yTexture = 0.0f;

for(y=1; y<heightMapHeight-1; y++)
{
if(renderMode==RENDER_FILLED || renderMode==RENDER_TEXTURED)
glBegin(GL_TRIANGLE_STRIP);
if(renderMode==RENDER_WIRE)
glBegin(GL_LINES);

//Render the row as a triangle strip

for(x=0; x<heightMapWidth-1; x++)
{
glTexCoord2f(xTexture, yTexture);
glVertex3f(terrain[((y*heightMapHeight)+x)][0],terrain[((y*heightMapHeight)+x)][1],terrain[((y*heightMapHeight)+x)][2]);

glTexCoord2f((xTexture + (1/heightMapWidth)), yTexture);
glVertex3f(terrain[((y*heightMapHeight)+(x+1))][0],terrain[((y*heightMapHeight)+(x+1))][1],terrain[((y*heightMapHeight)+(x+1))][2]);

glTexCoord2f(xTexture, (yTexture + (1/heightMapHeight)));
glVertex3f(terrain[(((y+1)*heightMapHeight)+x)][0],terrain[(((y+1)*heightMapHeight)+x)][1],terrain[(((y+1)*heightMapHeight)+x)][2]);

glTexCoord2f((xTexture + (1/heightMapWidth)),( yTexture + (1/heightMapHeight)));
glVertex3f(terrain[(((y+1)*heightMapHeight)+(x+1))][0],terrain[(((y+1)*heightMapHeight)+(x+1))][1],terrain[(((y+1)*heightMapHeight)+(x+1))][2]);

xTexture += (1.0f/heightMapWidth);
}
glEnd();

xTexture = 0.0f;
yTexture += (1.0f/heightMapHeight);
}


[edited by - schnegge on June 2, 2002 5:53:03 PM]

[edited by - schnegge on June 2, 2002 5:53:33 PM]

Share this post


Link to post
Share on other sites
and why does it texture each triangle and not each quad. i thought if i use trianglestrip i coud texture it like a quad...

Share this post


Link to post
Share on other sites

  • 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!