glGenerateMipmap没有任何效果的原因是什么?

huangapple go评论44阅读模式
英文:

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_NEARESTGL_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);

huangapple
  • 本文由 发表于 2023年2月27日 11:14:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75576488.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定