7.1. Obtaining Version Information
With the addition of the OpenGL Shading Language, the OpenGL version number was changed from 1.5 to 2.0. The number before the period is referred to as the major version number and the number after the period is referred to as the minor version number. This did not reflect a change in compatibility, as is often the case when a product's major version number is changed. Instead, the OpenGL ARB believed that inclusion of a high-level shading language was a major addition to OpenGL. To call attention to this important capability, the committee decided that a change to OpenGL's major version number was warranted.
This caused some incompatibility with applications that were written assuming that OpenGL would never have a major version number greater than 1. The OpenGL Shading Language also has a version number since it is expected that it too will have additional features added over time. Both of these values can be queried with the OpenGL function glGetString.
To write applications that will work properly in a variety of OpenGL environments and that will stand the test of time, be sure to properly query and parse the OpenGL and OpenGL Shading Language version strings. Both strings are defined as
where each component contains one or more digits. The vendor specification information and the release number are optional and might not appear in the version string. The version number is not a floating-point number, but a series of integers separated by periods.
To determine the OpenGL version number, call glGetString with the symbolic constant GL_VERSION. To determine the OpenGL Shading Language version, call glGetString with the symbolic constant GL_SHADING_LANGUAGE_VERSION. The shading language version that was approved at the time OpenGL 2.0 was approved was 1.10.
Listing 7.1 contains code for C functions that query and parse the OpenGL and OpenGL Shading Language version strings. Both functions assume that a valid OpenGL context already exists, and both return 0 for the major and minor number if an error is encountered. Values returned by these functions can be tested to see if the underlying implementation provides the necessary support.
Listing 7.1. C functions to obtain OpenGL and OpenGL Shading Language version information