Search code examples
c++openglmipmaps

OpenGL; gluBuild2DMipmaps Invalid Enumerant


I'm trying to implement mipmaps into an OpenGL Framework. After trying to use the tutorial at http://www.swiftless.com/tutorials/opengl/mipmap_generation.html I've tried the following

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





}

in which the commented lines starting with REMOVED - are what I am removing to minmap instead as per the swiftless.com tutorial. The get error code is creating this error window, which to me seems like the error is in the glActiveTexture or the glBindTexture lines, yet I've only altered the code past that. For the second parameter in gluBuild2DMipmaps I've tried using d, 1,2,3 and 4 but I'm still not quite sure what it is that's meant to go in there.

Can anyone explain the invalid enumerant error and where I need to be looking to fix that?


Solution

  • The error happens most probably in the second iteration:

    GL_NEAREST_MIPMAP_LINEAR is not a valid value for GL_TEXTURE_MAG_FILTER since mipmapping can only help with minification, not with magnification. You should use GL_NEAREST or GL_LINEAR instead.