Mesa + Linux: gl.h does not contain modern OpenGL

This is the environment I'm currently using: Eclipse-Luna, C ++ 11 on Linux Mint-Rebecca.

When I try to use modern OpenGL, for example with VAOs or VBOs, I get compiler errors so the methods cannot be resolved.

Example:

GLuint VaoID;                   //GLuint is working

glGenVertexArrays(1, &VaoID);

      

or

GLuint VboID;              
glGenBuffers(1, &VboID);
glBindBuffer(GL_ARRAY_BUFFER, VboID);
glBufferData(GL_ARRAY_BUFFER, vbo_size, data, usage);

      

I checked GL / gl.h, GL / glext.h and noticed that I only have OpenGL 1.x methods.

So, I checked the OpenGL version glxinfo | grep "OpenGL". Everything seems to be in order:

glxinfo|grep "OpenGL" 
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile 
OpenGL core profile version string: 3.3 (Core Profile) Mesa 10.1.3
OpenGL core profile shading language version string: 3.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 3.0 Mesa 10.1.3
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:

      

Trying to install or update packages again only means that everything is up to date.

  sudo apt-get install freeglut3 freeglut3-dev libglew1.5 libglew1.5-dev libglu1-mesa libglu1-mesa-dev libgl1-mesa-glx libgl1-mesa-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'libglew1.5-dev' for regex 'libglew1.5'
Note, selecting 'libglew-dev' instead of 'libglew1.5-dev'
Note, selecting 'libglew-dev' instead of 'libglew1.5-dev'
freeglut3 is already the newest version.
freeglut3-dev is already the newest version.
libglew-dev is already the newest version.
libglu1-mesa is already the newest version.
libglu1-mesa-dev is already the newest version.
libgl1-mesa-dev is already the newest version.
libgl1-mesa-glx is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 150 not upgraded.

      

So, is there a way to fix this without manually fiddling with the include directory?

And if not, how do I get an updated header that fits my version of OpenGL?

+3


source to share


2 answers


I checked GL / gl.h, GL / glex.h and noticed that I only have OpenGL 1.x.

For GL/gl.h

, this is actually how it should be. If you want to use OpenGL in a platform independent way, you can only rely on the GL 1.1 exported by the GL lib, and you shouldn't accept anything else in the headers either. GL/glext.h

should contain something more. But by default it will not provide function declarations for new functions. And the latest version of this file can always be obtained from the OpenGL site, by the way.

For all but GL 1.1, you have to use the GL extension mechanism, which basically means you need to query for function pointers for every GL> = GL 1.2 function at runtime. The header glext.h

provides function pointer type declarations and enumeration constants and additional data types. So it basically looks like this for every extension (and in this context, new functionality is seen as "extensions"):



#ifndef GL_ARB_vertex_buffer_object
#define GL_ARB_vertex_buffer_object 1
// new types
typedef ptrdiff_t GLsizeiptrARB; 
typedef ptrdiff_t GLintptrARB;
// constants for GLenum values
#define GL_BUFFER_SIZE_ARB                0x8764
#define GL_BUFFER_USAGE_ARB               0x8765
#define GL_ARRAY_BUFFER_ARB               0x8892
// ...
// function pointer tpes for every function
typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer);
typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers);
// ...
#ifdef GL_GLEXT_PROTOTYPES
// function declatations
GLAPI void APIENTRY glBindBufferARB (GLenum target, GLuint buffer);
GLAPI void APIENTRY glDeleteBuffersARB (GLsizei n, const GLuint *buffers); 
// ...
#endif
#endif /* GL_ARB_vertex_buffer_object */

      

Thus, function declarations are only effective if GL_GLEXT_PROTOTYPES

defined. But you shouldn't do that. It will only work if the GL lib will export those symbols, and this is not required on most platforms.

There is usually no need to manually load hundreds of GL function pointers. There are a couple of OpenGL loading libraries that have it all under the hood for you. And GLEW - which you already installed for some reason - is one of them, so you probably want to use it. Note that GLEW has some problems on its own, especially this breaks somewhat when used in conjunction with modern OpenGL contexts of the main profile, but it can still be used.

+3


source


I forgot to mention that I already included GL / glew.h in my headers. But that didn't fix the compilation errors. I checked the glew.h file with eclipse and it displayed several error messages. The topmost error line looks like this:

#error glext.h included before glew.h

      

Apparently the order includes questions here. After some involvement, the problem boiled down to a very simple code change. This is what I had:

#include <GLFW/glfw3.h>
#include <GL/glew.h>

      



The solution looks like this:

#include <GL/glew.h>
#include <GLFW/glfw3.h>

      

So, I just changed those two lines and it worked. Thanks again for your suggestions.

Also I removed GL / gl.h completely.

0


source







All Articles