使用 GLUT_3_2_CORE_PROFILE 时 OpenGL 错误 1282(无效操作)

OpenGL error 1282 (invalid operation) when using GLUT_3_2_CORE_PROFILE

我正在尝试通过在初始化 GLUT 时使用 GLUT_3_2_CORE_PROFILE 在我的 mac 上使用比默认 2.1 更新的 OpenGL 版本。但是,这会导致第一个 OpenGL 操作失败并显示 无效操作 。调用这第一个函数之前没有报错,没有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();

errorCheck的内容就是:

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

根据标题,错误 1282 仅由第二次调用 errorCheck 产生:

OpenGL error 1282: invalid operation

版本字符串被报告为 2.1 ATI-1.51.8 没有 GLUT_3_2_CORE_PROFILE4.1 ATI-1.51.8 有。这个较新版本的 OpenGL 是否需要进一步初始化?

glMatrixMode 是已弃用的 Fixed Function Pipeline 的一部分,在 OpenGL 3.2 核心配置文件中不可用。

GLUT 使用 Legacy Profile 作为所有创建的 OpenGL 上下文的默认配置。你必须省略 GLUT_3_2_CORE_PROFILE:

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);

您必须限制自己使用核心配置文件功能

核心配置文件和向前兼容模式之间的详细规格和差异可以在OpenGL specification - Khronos OpenGL registry

找到


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.

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.

参见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.