Search code examples
c++openglglut

OpenGL error 1282 (invalid operation) when using GLUT_3_2_CORE_PROFILE


I'm trying to use a more recent version of OpenGL than the default 2.1 on my mac by using GLUT_3_2_CORE_PROFILE when initialising GLUT. However, this causes the first OpenGL operation to fail with invalid operation. There is no error reported before calling this first function, and there was no error generated without GLUT_3_2_CORE_PROFILE.

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_3_2_CORE_PROFILE | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(500, 500);
glutCreateWindow("Demo");
glutDisplayFunc(displayListener);

errorCheck();
glMatrixMode(GL_PROJECTION);
errorCheck();

The contents of errorCheck is simply:

GLenum error;
while ((error = glGetError())) {
    std::cout << "OpenGL error " << error << ": " << gluErrorString(error);
}

As per the title, error 1282 is produced by the second call to errorCheck only:

OpenGL error 1282: invalid operation

The version string is reported as 2.1 ATI-1.51.8 without GLUT_3_2_CORE_PROFILE and 4.1 ATI-1.51.8 with. Is further initialisation required in this newer version of OpenGL?


Solution

  • glMatrixMode is part of the deprecated Fixed Function Pipeline and not available in OpenGL 3.2 core profile.

    GLUT uses Legacy Profile as default for all created OpenGL contexts. You have to omit GLUT_3_2_CORE_PROFILE:

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
    

    or you have to limit yourself to the core profile functionality.

    Detailed specifications and differences between the core profile and forward compatibility mode can be found at OpenGL specification - Khronos OpenGL registry


    See Khronos wiki - OpenGL Context:

    OpenGL version 3.0 introduced the idea of deprecating functionality. Many OpenGL functions were declared deprecated, which means that users should avoid using them because they may be removed from later API versions. OpenGL 3.1 removed almost all of the functionality deprecated in OpenGL 3.0. This includes the Fixed Function Pipeline.

    ....

    A new extension, ARB_compatibility, was introduced when OpenGL 3.1 was revealed. The presence of this extension is a signal to the user that deprecated or removed features are still available through the original entrypoints and enumerations. The behavior of such implementations is defined with a separate, much larger, OpenGL Specification. Thus, there was a backwards-compatible specification and a non-backwards compatible specification.
    However, since many implementations support the deprecated and removed features anyway, some implementations want to be able to provide a way for users of higher GL versions to gain access to the old APIs. Several techniques were tried, and it has settled down into a division between Core and Compatibility contexts.

    See Khronos wiki - Fixed Function Pipeline:

    OpenGL 3.0 was the last revision of the specification which fully supported both fixed and programmable functionality. Even so, most hardware since the OpenGL 2.0 generation lacked the actual fixed-function hardware. Instead, fixed-function processes are emulated with shaders built by the system. In OpenGL 3.2, the Core Profile lacks these fixed-function concepts. The compatibility profile keeps them around. However, most newer features of OpenGL cannot work with fixed function, even when it might seem theoretically possible for them to interact.

    See Khronos wiki - Legacy OpenGL:

    In 2008, version 3.0 of the OpenGL specification was released. With this revision, the Fixed Function Pipeline as well as most of the related OpenGL functions and constants were declared deprecated. These deprecated elements and concepts are now commonly referred to as legacy OpenGL.
    Legacy OpenGL is still supported by certain implementations that support core OpenGL 3.1 or higher and the GL_ARB_compatibility extension. Implementations that do not expose this extension do only offer features defined in the core OpenGL specification the implementation is based upon.