Question

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);
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top