c++ - 使用 GLUT_3_2_CORE_PROFILE 时出现 OpenGL 错误 1282(无效操作)

标签 c++ opengl glut

我在初始化 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.

关于c++ - 使用 GLUT_3_2_CORE_PROFILE 时出现 OpenGL 错误 1282(无效操作),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48249518/

相关文章:

c++ - QFile 既不读取也不打开我的文件

c++ - 在 OpenGL 中将纹理传递给着色器

c++ - Ray Tracer,阴影射线产生黑圈?

c++ - GLUT 显示空白窗口

c++ - 引起问题的纹理

c - 用顶点数组 : nothing displayed 绘制一系列点

c++ - 使用 GLUT 使 OpenGL 窗口居中

c++ - OpenGL多子窗口问题

C++:如何检索已安装的 Firefox 插件列表?

c++ - 为什么只能在头文件中实现模板?