OpenGL Core Profile Migration Issues

Migrating from an OpenGL Compatibiity to a Core Profile

Any graphical software written with OpenGL prior to 3.2 uses the so called legacy mode or compatibility profile. Migrating such a code to more recent OpenGL versions can be a task full of pitfalls and it implies a considerable share of tedious work. In the following I try to list the nastiest of those pitfalls:

  • With OpenGL 3.0 the immediate mode was removed, so that legacy commands like glVertex, glPerspective, gluLookat and the entire matrix stack are no longer supported.
    • As a consequence, one needs to calculate the viewing matrices by hand and render geometry using vertex buffer objects.
    • For that purpose one needs to utilize libraries like glm, glVertex or OpenFrameworks to simplify those tasks.
  • With an OpenGL 3.2 core profile one needs to strictly avoid OpenGL extensions:
    • Getting the GL_EXTENSIONS string will always return NULL.
    • Avoid tokens with the _EXT suffix like GL_MAX_EXT or GL_FUNC_REVERSE_SUBTRACT_EXT.
      • But the tokens GL_TEXTURE_MAX_ANISOTROPY_EXT and GL_TEXTURE_MAX_ANISOTROPY_EXT are still valid.
    • Avoid the texture formats GL_LUMINANCE, GL_LUMINANCE_ALPHA and GL_INTENSITY by replacing them with the GL_RED resp. GL_RG format and swizzeling the RGBA components accordingly with the texture parameters GL_TEXTURE_SWIZZLE_R, GL_TEXTURE_SWIZZLE_G, GL_TEXTURE_SWIZZLE_B and GL_TEXTURE_SWIZZLE_A.
  • GL_DEPTH_TEXTURE_MODE is no longer supported → use GL_DEPTH_COMPONENT instead.
    • Sampling a depth texture yields (z, 0, 0) and not (z, z, z). At least this applies to the NVIDIA drivers. The Intel drivers, for example, still return (z, z, z) depth samples.
  • With an OpenGL 4.6 core profile the tokens GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT and GL_TEXTURE_MAX_ANISOTROPY_EXT need to be replaced by their non-EXT counterparts.
  • On Apple MacOS X platforms one never gets an OpenGL 3.2 profile. What you get is an OpenGL 3.0 profile that behaves like a 3.2 core profile - ugh.