我已经加载了纹理,并将其显示在立方体和平面上。在平面和立方体相交的地方,有一些难看的视觉伪影。
下面两张图片说明了这个问题:
图 1 - 这是什么:
图 2 - 相同的场景,其他视角:
这是我加载图像的方式:
static const GLenum gl_format[4] = { GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_BGR, GL_BGRA };
GLuint LoadTGATexture(const char* filename)
{
//image is already loaded in --- unsigned char[] data - int width - int height - int components
unsigned int handle;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy);
glGenTextures(1, &handle);
glBindTexture(GL_TEXTURE_2D, handle);
glTexImage2D(GL_TEXTURE_2D, 0, components, width, height, 0, gl_format[components - 1], GL_UNSIGNED_BYTE, data);
gluBuild2DMipmaps(GL_TEXTURE_2D, components, width, height, gl_format[components - 1], GL_UNSIGNED_BYTE, data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy);
glBindTexture(GL_TEXTURE_2D, 0);
delete [] data;
return handle;
}
但是我该如何解决它,我的错误是什么?