英文:
why glGenerateMipmap makes no difference?
问题
我有一个尺寸为(720, 1080)的纹理,我想使用glGenerateMipmap
生成4个mipmap。我的代码如下:
float* texture = new float......
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &tbo);
glBindTexture(GL_TEXTURE_2D, tbo);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, 720, 1080, 0, GL_RGBA, GL_FLOAT, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 3);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glGenerateMipmap(GL_TEXTURE_2D);
当我放大或缩小纹理时,我没有看到任何差异,我哪里出错了?
英文:
I have a texture of size(720,1080),and I want to use glGenerateMipmap
to generate 4 mipmaps.My codes are:
float* texture = new float......
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &tbo);
glBindTexture(GL_TEXTURE_2D, tbo);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, 720, 1080, 0, GL_RGBA, GL_FLOAT, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL,0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 3);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glGenerateMipmap(GL_TEXTURE_2D);
I didn't see any differences when magnify or minify the texture, where I am wrong?
答案1
得分: 0
如评论中指出,GL_LINEAR_MIPMAP_LINEAR
不是纹理参数 GL_TEXTURE_MAG_FILTER
的有效值。有效的值是 GL_NEAREST
和 GL_LINEAR
。
无论如何,为了消除莫尔纹效应,我建议使用各向异性过滤(还请参阅采样器对象 - 各向异性过滤)。例如:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY, 8);
英文:
As pointed out in the comments, GL_LINEAR_MIPMAP_LINEAR
is not a valid value for the texture parameter GL_TEXTURE_MAG_FILTER
. Valid values are GL_NEAREST
and GL_LINEAR
.
Anyway, to get ride of Moire effect i suggest using Anisotropic filtering (alos see Sampler Object - Anisotropic filtering). e.g.:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY, 8);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论