Why is glGenVertexArrays defined for a C program but not a C++ program on Linux?

馋奶兔 提交于 2019-12-06 06:01:50

https://www.khronos.org/opengles/sdk/docs/man3/html/glGenVertexArrays.xhtml

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.

Solution : Use OpenGL ES 3.

Looking a the gl2.h header, it seems that the aformentioned function is not defined there. C++ has stricter rules with regard to function declaration and definition. In C, you may perfectly use a function which asn't been declared before hand, and the compiler will assume a certain prototype. In C++, any function must be at least declared before any use.

The section 5.2.2 - Function Call of the C++ specification, sub paragraph 2 indicates that:

Note: If a function or member function name is used, and name lookup (3.4) does not find a declaration of that name, the program is ill-formed. No function is implicitly declared by such a call. — end note

That is where the difference lies with C. This may however indicate a deeper problem: either you are using the wrong header, and linking with an OpenGL implementation which support that function, or somehow, the header should contain that declaration and does not. My first guess would be that you should probably double check which OpenGL implementation you are effectively linking against, and whether the header you are using is the correct one.

However, it is also possible that this OpenGL standard keeps an definition of that function as an extension, or that the function is visible by the linker because the driver supports a higher standard or extension. Relying on that feature is of course not recommended without first checking that the corresponding extension is actually supported by the driver.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!