2

Sorry if this question's title was phrased poorly, but I have a class with a member function that in turn calls a couple of OpenGL functions:

class StateSet
{
public:
    StateSet();
    // ...

    inline void SetVertexAttributeEnabled(GLuint location,bool enabled)
    {
        if(m_GL_VERTEX_ATTRIB_ARRAY_ENABLED[location] == enabled) {
            return;
        }

        m_GL_VERTEX_ATTRIB_ARRAY_ENABLED[location] = enabled;
        if(enabled) {
            glEnableVertexAttribArray(location);
        }
        else {
            glDisableVertexAttribArray(location);
        }
    }
    // ...

When trying to compile this, I get

'glEnableVertexAttribArray' was not declared in this scope
'glDisableVertexAttribArray' was not declared in this scope

If I don't make the function inline (take out the 'inline' keyword) and define the function in the corresponding source file, it works fine. The source file doesn't have any additional includes, it just includes the header file, which in turn includes:

#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glext.h>

So why would inlining make the compiler unable to 'see' the OpenGL function calls?

This doesn't happen for all OpenGL functions either -- I can compile if I try calling glDrawArrays, glGet[], etc.

More information:

All the includes for the header and source file in question are:

#include <vector>
#include <cassert>
#include <sstream>
#include <iostream>

#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glext.h>

OpenGL and its context and everything should be set up by Qt; this class is being used in a Qt application where I can already call the functions (glEnable/DisableVertexAttribArray) and everything seems to be set up ok.

Prismatic
  • 3,338
  • 5
  • 36
  • 59
  • 1
    Not related to your problem but: [you may wish to brush up on your understanding of `inline`](http://stackoverflow.com/questions/1759300/when-should-i-write-the-keyword-inline-for-a-function-method) – Jason C Mar 05 '14 at 02:44
  • 1
    Related to your problem: Can you show us exactly what headers (in order, and even ones seemingly unrelated to OpenGL) your source and your header file include? – Jason C Mar 05 '14 at 02:46

2 Answers2

0

This also might be a namespace issue, the things that are working might be #defines in the header which wouldn't be affected by the namespace, while in one of the files an #include statement might be inside of a namespace which is affecting normal function definitions. Sorry, just kind of guessing, I am absolutely positive there is something weird going on though.

user26347
  • 594
  • 3
  • 4
0

I was able to get around this by passing a define option to the compiler instead of relying on the following define macro:

#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glext.h>

I don't really know why that ended up working. I think it implies that when the compiler first reads in GL/glext.h, GL_GLEXT_PROTOTYPES isn't defined.

I'm not sure in what order preprocessor #defines take effect but I guess its possible that GL/glext.h got included somewhere else first?

Prismatic
  • 3,338
  • 5
  • 36
  • 59