opengl 为什么glGenerateMipmap没有区别?

vmjh9lq9  于 2023-03-02  发布在  其他
关注(0)|答案(1)|浏览(142)

我有一个大小为(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);

我没有看到任何差异时,放大或缩小纹理,我错了吗?

iq3niunx

iq3niunx1#

正如评论中指出的,GL_LINEAR_MIPMAP_LINEAR不是纹理参数GL_TEXTURE_MAG_FILTER的有效值。有效值为GL_NEARESTGL_LINEAR。无论如何,要获得Moire effect的好处,我建议使用Anisotropic filtering(也请参阅采样对象-各向异性过滤)。例如:

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

相关问题