glGenerateMipmap- identifier not found?

9k views Asked by At

I'm trying to implement glGenerateMipmap so I can go on to recolour each level of a cube I've rendered, except the program won't compile giving the error

'error C3861: 'glGenerateMipmap': identifier not found'

I've included '#include ' and inside the header the definition seems to exist (though inside an IF statement? see below) so I was wondering if there was a way to redefine/locate it somehow so the program will compile or run, and if not if there was another method to automatically generating mipmaps?

#ifdef GL_GLEXT_PROTOTYPES
...
...
GLAPI void APIENTRY glGenerateMipmap (GLenum);
...
#endif /* GL_GLEXT_PROTOTYPES */

Many thanks, Chris

2

There are 2 answers

1
datenwolf On

This is not the correct way to access OpenGL extensions. The correct way is a little bit involved, as you must not redefine symbols that may be imported from libraries. On Windows not a big issue since there are only OpenGL-1.1 symbols exported. But on pretty much any other OS there are additional symbols exported by the OpenGL library.

I strongly advise using a extension loader library, due to the simple fact that correctly loading extensions is tedious. So just get GLEW from http://glew.sourceforge.net and be done with it. Or use some OpenGL framework that also provides extension management like GLFW.

Just look at how to correctly load OpenGL extensions, to understand why:

typedef GLAPI void APIENTRY (*__MYGLEXTFP_GLGENERATEMIPMAPS)(GLenum);
__MYGLEXTFP_GLGENERATEMIPMAP __myglextGenerateMipmaps;
#define glGenerateMipmaps __myglextGenerateMipmaps;

and later in the extension initialization:

#ifdef WIN32
#define __MYGLEXT_GetProcAddress wglGetProcAddress
#endif
#ifdef GLX
#define __MYGLEXT_GetProcAddress glXGetProcAddress
#endif

__myglGenerateMipmap = 
    (__MYGLEXTFP_GLGENERATEMIPMAPS) __MYGLEXT_GetProcAddress("glGenerateMipmaps");

Looks quite messy, you agree? However this is the only clean way to do it. It does get even more involved if one uses multiple OpenGL contexts under Windows, as the function pointers of Windows OpenGL extentension functions may different between contexts.

3
tibur On

glGenerateMipmaps is an extension. Consider using glew to load it.