<< May 2018 | Home

Lifting deprecated OpenGL code to modern equivalent

OpenGL 3.0 to OpenGL 3.3+

OpenGL has been around a long time. This has necessitated some pretty aggressive, or we could call it, slightly odd, deprecation over time. This was necessary to keep API relevant.

Until version 3.0, all versions of OpenGL were fully backwards compatible with earlier ones.

OpenGL 3.1 is just awkward and short-lived, it is probably not worth explaining; we'll ignore it.

In 3.2, OpenGL was effectively split into two profiles, core and compatibility. An implementation was only required to define core, so compatibility is not guaranteed to be available.

On some platforms, like Windows, developers will find that they have access to the compatibility profile and they can gracefully or incrementally move functionality towards the new standard. On other platforms, like Apple OSX there is a hard cut. They chose to support OpenGL 2.1, and the pretty much ignored the in-between, and then, made the jump to OpenGL 3.3. Apple also chose to only implement OpenGL 3.3 core. This means there is no graceful support of older functionality.

Developers finding themselves having to lift OpenGL code in their title or package may benefit from the reference table below. It roughly details the mapping between OpenGL 2.1 era functionality and how to replace it in OpenGL 3.3 core and higher.

Hopefully useful for others as well as us!

Deprecated functionalityReplaceable by (in OpenGL 3.3)
Fixed function pipelineShaders
glRotate*/glTranslate*/glScale*
/glMatrixMode/glLoadMatrix/glMultMatrix etc.
Use you own matrix math or known open source libraries. Did you really use it anyway?
glTexEnvfTexture blending should now be done in fragment shaders.
gluBuild2DMipmaps Use the GL_GENERATE_MIPMAP texture parameter or the glGenerateMipmap function. Set the max mipmap level and the base mipmap level using

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4);
glEnable(GL_POINT_SMOOTH)Emulate this in a shader if you miss it
glEnable(GL_TEXTURE_2D)No longer. Ue glActiveTexture(GL_TEXTUREn) and bind the texture to the n-th texture unit.
glVertex*/glColor*/glNormal*/glTexCoord*Use vertex buffer objects (VBO) and vertex attribute objects (VAO) to control vertices. Draw using the glDraw{Arrays, Elements, RangeElements, InterleavedElements} family of functions.
glPolygonMode(GL_FRONT, GL_LINE) or glPolygonMode(GL_BACK, GL_LINE) In OpenGL 3.0 or above, core profile, only the combined front and back face enumerant is valid, offering a single mode enumerant GL_FRONT or GL_BACK results in an INVALID_OPERATION. Therefore the only valid call is glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);