为什么glGenVertexArray是为C程序定义的,而不是在Linux上的C ++程序?
请考虑以下文件:
#include <SDL.h>
#include <GLES2/gl2.h>
int main() {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *window = SDL_CreateWindow("Test", 0, 0, 200, 200, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
SDL_GLContext context = SDL_GL_CreateContext(window);
GLuint vao;
glGenVertexArrays(1, &vao);
}
如果上面的是test.c,那么下面的行代码)完美地工作:
If the above is test.c, then the following line (compiling as C code) works perfectly:
gcc test.c -I/usr/include/SDL2 -lGLESv2 -lSDL2
但是,下一个(编译为C ++代码)不会:
This next one (compiling as C++ code), however, does not:
gcc -x c++ test.c -I/usr/include/SDL2 -lGLESv2 -lSDL2
我得到的错误是:
test.c: In function ‘int main()’:
test.c:9:27: error: ‘glGenVertexArrays’ was not declared in this scope
glGenVertexArrays(1, &vao);
我在x86 Linux上使用gcc 4.8.2编译,使用SDL 2.0和OpenGL ES 2.0。
I am compiling this on x86 Linux with gcc 4.8.2, using SDL 2.0 and OpenGL ES 2.0.
发生了什么事?许多其他OpenGL ES 2.0调用(glDrawArrays,glGenBuffers等)与C和C ++完美配合。另外,是不是C ++应该能够调用C库,特别是系统的(应该)设计来防止函数名称破坏?
What is going on? Many of the other OpenGL ES 2.0 calls that I make (glDrawArrays, glGenBuffers, etc.) work perfectly well with both C and C++. Additionally, isn't C++ supposed to be able to call C libraries, especially system ones that (should) be designed to prevent function name mangling?
什么是错误,如何解决此问题?
What is wrong, and how can I fix this?
https://www.khronos.org/opengles/sdk/docs/man3/html/glGenVertexArrays.xhtml
前面的答案也是正确的,但并不真正给出一个解决方案。也不是我的实际。这只是 glGenVertexArrays
不支持OpenGLES 2。
The previous answer is also correct but doesn't really gives a solution. Nor mine actually. It's just that glGenVertexArrays
is not supported by OpenGLES 2.
解决方案:使用OpenGL ES 3。
Solution : Use OpenGL ES 3.