views:

328

answers:

1

Hi, I am creating a simple opengl application which obviously includes some 3d-objects and textures. My problem is however that artifacts appear on every texture. These come in the form of triangles along the edges.

I have noticed that it disappears as soon as I move the view-point closer to texture it renders perfectly. Therefore I have a suspicion that it has something to do, either with the mipmapping or the z-buffer. Please note that all texture-coordinates are loaded from a .3ds-file and all of them are verified to be within the range of 0-1.

Here are a picture of my problem:

Picture 1

The textures are loaded like this:

//Texture parameters
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

//Define the 2d texture
glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, array);

//Create 2d mipmaps
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, GL_RGBA, GL_UNSIGNED_BYTE, array);
+1  A: 

When I was programming using DirectX, the near plane / far plane distance ratio caused artifacts in the edges.

In my case, if near plane was 1 unit away from 'camera' and far plane was 10000 units away, the ratio is 1/10000 and it created problems. If i set the near plane to 10 or 100, the ratio becomes bigger. It solved the jagged edges problem.

I don't know if/how it is applicable in OpenGL, but you might want to check it out.

Thats Z-Buffer prceision. If you had upped to a 24-bit Z-buffer you would've seen the problems go away too. Mind its an important lesson in setting your units appropriately. ie don't have an object that is 0.01 units wide with a max draw distance of 10000 units ;)
Goz
Nice, changing the near plane from 0.1 to 10 solved the problem!
Håkon
@Goz... Yeah. DirectX also dealt with something called w-buffer. It was all related. It's been so long since I last used DirectX that I only remember the hard learnt lesson :D - keep the ratio high - and not the exact details.