Mesa + Linux:gl.h不包含现代OpenGL [英] Mesa + Linux : gl.h does not contain modern OpenGL

查看:548
本文介绍了Mesa + Linux:gl.h不包含现代OpenGL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我目前使用的环境:Eclipse-Luna,C ++ 11在Linux Mint-Rebecca。

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

当我尝试使用现代的OpenGL像VAO或VBO时,我得到编译器错误,使得方法无法解决。

When I try to use modern OpenGL like with VAOs or VBOs I get Compiler Errors such that methods could not be resolved.

例如:

GLuint VaoID;                   //GLuint is working

glGenVertexArrays(1, &VaoID);

或:

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

我检查了GL / gl.h,GL / glext.h并注意到我只有OpenGL 1.x方法在那里。

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

所以我检查了我的OpenGL版本glxinfo | grepOpenGL。这似乎很好:

So I checked my OpenGL version glxinfo|grep "OpenGL". Which seems to be fine:

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 the packages again only states 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.

那么有没有手动修复include目录的方法呢?

So is there a way of fixing this without manually messing with the include directory?

如果没有如何获得一个适合我的OpenGL版本的最新的头文件?

And if there isn't how do I get an up to date header fitting my OpenGL version?

推荐答案


我检查了GL / gl.h,GL / glex.h并注意到我只有
OpenGL 1.x方法。

I checked the GL/gl.h, GL/glex.h and noticed that I have only got OpenGL 1.x methods in there.

对于 GL / gl.h ,这实际上是 em>是。如果你想以一种平台无关的方式使用OpenGL,你只能依赖于由GL lib 导出的GL 1.1,并且不应该在标题中再考虑任何东西。 GL / glext.h 实际上应该包含更多内容。但是默认情况下,它不会为较新的函数提供函数声明。您可以随时从OpenGL网站获取该文件的最新版本, btw。

For GL/gl.h, that is actually how it is supposed to be. If you want to use OpenGL in a platform-independent manner, you can only rely on GL 1.1 being exported by the GL lib, and should also not assume anything more in the headers. GL/glext.h should actually contain something more. But by default, it will not provide function declarations for the newer functions. A recent version of that file can always be obtained from the OpenGL website, btw.

对于GL 1.1之外的任何内容,都应该使用GL的扩展机制,这意味着您必须查询 em> GL function> = GL 1.2在运行时。 glext.h 头提供函数指针类型声明,枚举常量和附加数据类型。因此,对于每个扩展,这基本上是这样的(并且新的核心功能在这个上下文中被认为是扩展):

For everything beyond GL 1.1, you should use GL's extension mechanism, which basically means that you have to query the function pointers for each and every GL function >= GL 1.2 at run time. The glext.h header provides the function pointer type declartations, and enum constants, and additional data types. So this basically looks like this for each extension (and new core functionality are considered "extensions" in this context):

#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 */

所以函数声明只有在定义了 GL_GLEXT_PROTOTYPES 时才有效。但你不应该这样做。它只有在GL库出现这些符号时才会工作,并且这在大多数平台上不是必需的。

So the function declarations are only effective if GL_GLEXT_PROTOTYPES has been defined. But you shouldn't do that. It will only work if the GL lib happens to export these symbols, and that is not required on most platforms.

通常,不想加载数百个GL函数指针。有几个 OpenGL加载库,它们为您提供了所有这些。由于某些原因,您已安装的 GLEW 是其中之一,因此您可能需要使用它。注意,GLEW本身有一些问题,特别是当它与现代核心配置文件OpenGL上下文结合使用时,它有点被破坏,但它仍然可以使用。

Usually, one does not want to load hundreds of GL function pointers manually. There are a couple of OpenGL loading libraries which hanlde all this for you under the hood. And GLEW - which you already installed for some reason - is one of those, so you probably want to use it. Note that GLEW has some issues on its own, notably it is somewhat broken when used in conjunction with modern core profile OpenGL contexts, but it can still be used.

这篇关于Mesa + Linux:gl.h不包含现代OpenGL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆