c-Mesa Linux:gl.h不包含现代OpenGL
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c-Mesa Linux:gl.h不包含现代OpenGL,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3767字,纯文字阅读大概需要6分钟。
内容图文
![c-Mesa Linux:gl.h不包含现代OpenGL](/upload/InfoBanner/zyjiaocheng/946/3e2a7f4c51934a82a726dce38aa61fd6.jpg)
我当前使用的环境是:Eclipse-Luna,Linux Mint -Rebecca上的C 11.
当我尝试将现代OpenGL与VAO或VBO一起使用时,出现编译器错误,导致无法解析方法.
例如:
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方法.
因此,我检查了我的OpenGL版本glxinfo | grep“ OpenGL”.这似乎很好:
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:
再次尝试安装或更新软件包仅表明所有信息都是最新的.
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目录?
如果没有,该如何获取适合我的OpenGL版本的最新标头?
解决方法:
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,实际上应该是这样.如果要以独立于平台的方式使用OpenGL,则只能依靠GL lib导出的GL 1.1,并且也不应在标头中假设更多内容. GL / glext.h实际上应该包含更多内容.但是默认情况下,它将不为较新的函数提供函数声明.始终可以从OpenGL网站btw获得recent version of that file.
对于GL 1.1以外的所有内容,都应使用GL的扩展机制,这基本上意味着您必须在运行时查询每个GL => GL 1.2的函数的函数指针. glext.h标头提供函数指针类型的声明,枚举常量和其他数据类型.因此,对于每个扩展,基本上都是这样(在这种情况下,新的核心功能被视为“扩展”):
#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 lib恰好导出这些符号时才起作用,而在大多数平台上则不需要.
通常,您不想手动加载数百个GL函数指针.有一些OpenGL loading libraries可以在引擎盖下为您提供所有这些服务.出于某种原因已经安装的GLEW是其中之一,因此您可能要使用它.请注意,GLEW本身有一些问题,特别是当与现代核心配置文件OpenGL上下文结合使用时,它有些破损,但仍然可以使用.
内容总结
以上是互联网集市为您收集整理的c-Mesa Linux:gl.h不包含现代OpenGL全部内容,希望文章能够帮你解决c-Mesa Linux:gl.h不包含现代OpenGL所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。