I want to make sure that my application conforms to OpenGL 2.1. How can I check this?
Because my computer supports GL4.4, even if I use, for example, glGenVertexArrays()
, it will work successfully. But glGenVertexArrays()
is only available with GL3+.
So, I want to verify that my app only uses GL2.1 functionality. One way is to run it on my old PC that support only GL2.1, but I'm looking for an easier way.
Click Start, type dxdiag, and press Enter to access a diagnostic tool listing the graphics card information.
If you find an extension loader that supports generating version specific headers, as described by @datenwolf, that's probably your easiest solution. There's another options you can try if necessary.
The official OpenGL headers you can find at https://www.opengl.org/registry contain the definitions grouped by version, and enclosed in preprocessor conditions. The layout looks like this:
...
#ifndef GL_VERSION_2_1
#define GL_VERSION_2_1 1
// GL 2.1 definitions
#endif
#ifndef GL_VERSION_3_0
#define GL_VERSION_3_0 1
// GL 3.0 definitions
#endif
#ifndef GL_VERSION_3_1
#define GL_VERSION_3_1 1
// GL 3.1 definitions
#endif
...
You should be able to include the official header at least for a version test. If you disable the versions you do not want to use by defining the corresponding pre-processor symbol, you will get compile errors if you are trying to use features from those versions. For example for GL 2.1:
#define GL_VERSION_3_0 1
#define GL_VERSION_3_1 1
#define GL_VERSION_3_2 1
#define GL_VERSION_3_3 1
#define GL_VERSION_4_0 1
#define GL_VERSION_4_1 1
#define GL_VERSION_4_2 1
#define GL_VERSION_4_3 1
#define GL_VERSION_4_4 1
#define GL_VERSION_4_5 1
#include <GL/glext.h>
// your code
Try https://github.com/cginternals/glbinding. It's an OpenGL wrapper library which supports exactly what you ask for:
Feature-Centered Header Design
The OpenGL API is iteratively developed and released in versions, internally (for the API specification) named features. The latest feature/version of OpenGL is 4.5. The previous version are 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 2.0, 2.1, 3.0, 3.1, 3.2, 3.3, 4.0, 4.1, 4.2, 4.3, and 4.4. OpenGL uses a deprecation model for removing outdated parts of its API which results in compatibility (with deprecated API) and core (without deprecated API) usage that is manifested in the targeted OpenGL context. On top of that, new API concepts are suggested as extensions (often vendor specific) that might be integrated into future versions. All this results in many possible specific manifestations of the OpenGL API you can use in your program.
One tough task is to adhere to one agreed set of functions in your own OpenGL program (e.g., OpenGL 3.2 Core if you want to develop for every Windows, macOS, and Linux released in the last 4 years). glbinding facilitates this by providing per-feature headers by means of well-defined/generated subsets of the OpenGL API.
All-Features OpenGL Headers
If you do not use per-feature headers the OpenGL program can look like this:
#include <glbinding/gl/gl.h> // draw code gl::glClear(gl::GL_COLOR_BUFFER_BIT | gl::GL_DEPTH_BUFFER_BIT); gl::glUniform1i(u_numcubes, m_numcubes); gl::glDrawElementsInstanced(gl::GL_TRIANGLES, 18, gl::GL_UNSIGNED_BYTE, 0, m_numcubes * m_numcubes);
Single-Feature OpenGL Headers
When developing your code on Windows with latest drivers installed, the code above is likely to compile and run. But if you want to port it to systems with less mature driver support (e.g., macOS or Linux using open source drivers), you may wonder if
glDrawElementsInstanced
is available. In this case, just switch to per-feature headers of glbinding and choose the OpenGL 3.2 Core headers (as you know that at least this version is available on all target platforms):#include <glbinding/gl32core/gl.h> // draw code gl32core::glClear(gl32core::GL_COLOR_BUFFER_BIT | gl32core::GL_DEPTH_BUFFER_BIT); gl32core::glUniform1i(u_numcubes, m_numcubes); gl32core::glDrawElementsInstanced(gl32core::GL_TRIANGLES, 18, gl32core::GL_UNSIGNED_BYTE, 0, m_numcubes * m_numcubes);
If the code compiles than you can be sure it is OpenGL 3.2 Core compliant. Using functions that are not yet available or relying on deprecated functionality is prevented.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With