【问题标题】:OpenGL; gluBuild2DMipmaps Invalid EnumerantOpenGL; gluBuild2DMipmaps 枚举数无效
【发布时间】:2018-02-18 23:16:45
【问题描述】:

我正在尝试将 mipmap 实现到 OpenGL 框架中。在尝试使用http://www.swiftless.com/tutorials/opengl/mipmap_generation.html 的教程后,我尝试了以下方法

for (int i=0;i<used_textures;i++)
{
        //glEnable( GL_TEXTURE_2D );
        GLGETERROR("Texture set up a");

        glActiveTexture(GL_TEXTURE0+i);
    glBindTexture(GL_TEXTURE_2D,texhandles[i]);//bind texture - assume all are 2D
    GLGETERROR("Texture set up aa");
    for (int d=0;d<global_textures[i].depth;d++)
    {
        switch(global_textures[i].comp)
        {
        //There are 4 cases in the actual code but case 3 is the only one that is used based on the data file.
        case 3:
            //REMOVED  - glTexImage2D( GL_TEXTURE_2D,  d, GL_RGB32F, global_textures[i].sx>>d, global_textures[i].sy>>d, 0, GL_RGB, GL_UNSIGNED_BYTE, global_textures[i].texMap[d] );
            gluBuild2DMipmaps(GL_TEXTURE_2D, 4, global_textures[i].sx >> d, global_textures[i].sy >> d, GL_RGB32F, GL_UNSIGNED_BYTE, global_textures[i].texMap[d]);
            break;

        }
    }
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_LINEAR );
    //REMOVED - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    //REMOVED - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );





}

其中以 REMOVED - 开头的注释行是我根据 swiftless.com 教程删除到 minmap 的内容。获取错误代码正在创建this error window,在我看来,错误出现在 glActiveTexture 或 glBindTexture 行中,但我只是更改了代码。对于 gluBuild2DMipmaps 中的第二个参数,我尝试过使用 d、1、2、3 和 4,但我仍然不太确定这意味着什么。

谁能解释无效的枚举错误以及我需要在哪里解决这个问题?

【问题讨论】:

    标签: c++ opengl mipmaps


    【解决方案1】:

    错误很可能发生在第二次迭代中:

    GL_NEAREST_MIPMAP_LINEAR 不是GL_TEXTURE_MAG_FILTER 的有效值,因为 mipmapping 只能帮助缩小,不能放大。您应该改用GL_NEARESTGL_LINEAR

    【讨论】:

    • 谢谢,它现在正在渲染盒子。如果您可以在我之前链接的代码中看到一个明显的问题,请快速跟进,在更改之前它看起来像 like this 并且使用 mipmapping 它看起来像 this,无论放大多少都没有纹理。这是预期的还是我在其他地方搞砸了?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多