Jump to content
  • Advertisement
Sign in to follow this  
Darobat

Terrain Woes

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

Free Image Hosting at www.ImageShack.us Greetings Above is a pic of my terrain rendered in wire frame and then rendered again with a texture. In the textured one, you'll see that in the red circle is a part of the terrain that didn't exist in the wireframe version of it. Any ideas what would be causing it?
bool CHeightmap::Render(float _x, float _y, float scale, bool wireframe)
{
	float startX, startY;
	float curX, curY, curZ;

	startX = (_x - (float)width / 2.0f) * scale;
	startY = (_y - (float)height / 2.0f) * scale;
	if(!wireframe)
	{
		EnableTextures();
		texGrass.Bind();
	}

	glBegin(wireframe ? GL_LINES : GL_QUADS);
		for(int y = 0; y < (signed)height; y++)
		{
			for(int x = 0; x < (signed)width; x++)
			{
				// Bottom left
				glTexCoord2i(0, 0);
				curX = (startX + x) * scale;
				curZ = (startY + y + 1) * scale;
				curY = vertices[(y + 1) * width + x] * scale;
				glVertex3f(curX, curY, curZ);
				// Bottom right
				glTexCoord2i(1, 0);
				curX = (startX + x + 1) * scale;
				curZ = (startY + y + 1) * scale;
				curY = vertices[(y + 1) * width + x + 1] * scale;
				glVertex3f(curX, curY, curZ);
				// Top right
				glTexCoord2i(1, 1);
				curX = (startX + x + 1) * scale;
				curZ = (startY + y )* scale;
				curY = vertices[y * width + x + 1] * scale;
				glVertex3f(curX, curY, curZ);
				// Top left
				glTexCoord2i(0, 1);
				curX = (startX + x) * scale;
				curZ = (startY + y) * scale;
				curY = vertices[y * width + x] * scale;
				glVertex3f(curX, curY, curZ);				
			}
		}
	glEnd();
	DisableTextures();
	return true;
}

You may remeber this code from a while back when I posted a question on why the terrain was invisible. Well now its visible but with a minor problem. Also, if I decrease the scale/zoom out, I see a single line sticking out where the strange part is. Thanks

Share this post


Link to post
Share on other sites
Advertisement
I think the problem is that you are reaching out of the array. Would you like me to show you or would you prefer to find it yourself?

Notice that the problem is visable because of the diffrence between lines and quads and has nothing to do with textures.

Share this post


Link to post
Share on other sites
ok:

for(int y = 0; y < (signed)height; y++)
...
curY = vertices[(y + 1) * width + x] * scale;

so:

if y = height-1 then the index into vertices is height * width + x which is bigger than height * width which I'm guessing is the size of your array.

Share this post


Link to post
Share on other sites
Thankyou sooo much! That fixed it!
Another problem though
Free Image Hosting at www.ImageShack.us

What the hell is going on with the water in the ciricled area?
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
When I turn off blending, you can't see it as much but there is a tiny line runing down the water where it is screwing up.
Thanks.

Share this post


Link to post
Share on other sites
Like already said, changing your geometry would be better...Z fighting occurs when polygons are too close together--rounding errors cause one polygon to be on top in one frame, and the other polygon in the next frame. If you move the polygons away from eachother, things should work fine...

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!