Terrain Woes

Started by
28 comments, last by zedzeek 19 years, 3 months ago
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
--------------------C++ Home - Check it out!Lol... - Amazing video
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.
Don't shoot! I'm with the science team.....
Please show me. I am completly out of ideas on this one... :S
--------------------C++ Home - Check it out!Lol... - Amazing video
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.
Don't shoot! I'm with the science team.....
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.
--------------------C++ Home - Check it out!Lol... - Amazing video
z-fight? :)
How exactly would one fix it?
--------------------C++ Home - Check it out!Lol... - Amazing video
One solution is to increase znear/zfar ratio and/or increase z-buffer bpp.
Better is to modify the geometry and avoid near overlapping.
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...
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.
I'm kinda lost on what your talking about... What function would I use to do that?
--------------------C++ Home - Check it out!Lol... - Amazing video

This topic is closed to new replies.

Advertisement