glWindowPos2i was not declared in this scope

家住魔仙堡 提交于 2020-01-05 08:27:27

问题


I'm migrating an OpenGL program over to C++. I have all of the library includes transitioned except for one. In my display function, I have this line (to display text on the screen):

glWindowPos2i(5,5);

This works fine when I run the program as a .c or when I run it as a .cpp in OSX. But I need it to compile as a .cpp on Linux, also. When I go to compile it there, I get this error:

error: 'glWindowPos2i' was not declared in this scope

I can't figure out if this is a missing library or what is going on. Does anyone know what I need to do to get this line to compile?


回答1:


That is because glWindowPos__ (...) started life out as an extension: GL_ARB_window_pos. It was integrated into core OpenGL in version 1.4.

You are fortunate on OS X to have an implementation of OpenGL that supports OpenGL 2.1/3.2 (in newer versions) out-of-the-box. In Linux, the situation is much different. You have to use the GLX API to load the glWindowPos__ (...) function entry-points at run-time (because they are provided by the display driver).

The easiest way to solve this in all honesty would be to integrate the GLEW library into your build environment for non-OS X targeted builds. You will encounter this same problem in Microsoft Windows, because Windows only ships with OpenGL 1.1 libraries out-of-the-box - display drivers extend it at run-time just as in Linux.

GLEW will take care of loading the function entry-points that are not provided with the shipping OpenGL libraries on both Windows and Linux, and make the whole process painless. Just remember to disable GLEW when you build your software on OS X, it is not necessary and it actually creates more problems if you do link to it in OS X.



来源:https://stackoverflow.com/questions/19108814/glwindowpos2i-was-not-declared-in-this-scope

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