Forcing OpenGL Core Profile Only
Is there a compiler flag or another way of forcing OpenGL core profile only? I want to get an error whe开发者_如何转开发n i use deprecated functions like glRotatef and so on.
EDIT1: I am using Linux, however, i am also interested in knowing how to do this in Windows
EDIT2: I would prefer to get an error at compile time, but runtime error would be ok as well.
You could compile your code using gl3.h
instead of gl.h
.
http://www.opengl.org/registry/api/gl3.h
Try wglCreateContextAttribsARB() with WGL_CONTEXT_CORE_PROFILE_BIT_ARB
.
Or glXCreateContextAttribsARB with GLX_CONTEXT_CORE_PROFILE_BIT_ARB
.
You might find this example useful as a testbed.
Depends on what creates your OpenGL context.
If you're using GLFW (which I sincerely recommend for standalone OGL window apps), then you can do before you create the window:
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR,3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR,1);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE,GLFW_OPENGL_CORE_PROFILE);
// the last line shouldn't be necessary
// as you request a specific GL context version -
// - at least my ATI will then default to core profile
Note that if you request a pre-3.0 GL context on modern hardware/drivers, you're likely to receive a newest possible context in compatibility mode instead. Check what your GPU returns from glGetString(GL_VERSION)
to make sure.
If you use another API for creation of OpenGL context, check its reference manual for similar functions.
BTW:
I believe it's impossible to get an error in compile time - your compiler can't be aware what OpenGL context you will receive after your request (if any). The correct way of ensuring that you're not using out-of-version functionality is testing for glGetError()
.
Also, I recommend using the gl3w
extension wrapper if you compile for Windows.
I have found another way to do it using the Unofficial OpenGL Software Development Kit:
http://glsdk.sourceforge.net/docs/html/index.html
By using the 'GL Load' component its possible to load a core profile of OpenGL and to remove compatibility enums and functions for versions of OpenGL 3.1 or greater. A short howto can be found here:
https://www.opengl.org/wiki/OpenGL_Loading_Library#Unofficial_OpenGL_SDK
精彩评论