• 11
• 27
• 9
• 20
• 31

# Terrain Woes

This topic is 4822 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 on other sites
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 on other sites
Please show me. I am completly out of ideas on this one... :S

##### 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 on other sites
Thankyou sooo much! That fixed it!
Another problem though

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.

z-fight? :)

##### Share on other sites
How exactly would one fix it?

##### Share on other sites
One solution is to increase znear/zfar ratio and/or increase z-buffer bpp.
Better is to modify the geometry and avoid near overlapping.

##### 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...