【问题标题】:Create Core context with GLUT/FreeGLUT?使用 GLUT/FreeGLUT 创建核心上下文?
【发布时间】:2018-07-06 10:31:01
【问题描述】:

我正在开发一个使用freeglutGLEW 的项目。为了在我的程序中使用顶点和片段着色器,我需要使用的最低 OpenGL 版本是3.3。我检查了 OpenGL 版本和 GLSL 版本,this 是结果:

[cyclonite@localhost ~]$ glxinfo | grep OpenGL 
OpenGL vendor string: Intel Open Source Technology Center 
OpenGL renderer string: Mesa DRI Intel (R) HD Graphics 620 (Kaby Lake GT2) 
OpenGL core profile version string: 4.5 (Core Profile) Mesa 17.3.3 
OpenGL core profile shading language version string: 4.50 
OpenGL core profile context flags: (none) 
OpenGL core profile profile mask: core profile 
OpenGL core profile extensions: 
OpenGL version string: 3.0 mesa 17.3.3 
OpenGL shading language version string: 1.30 
OpenGL context flags: (none) 
OpenGL extensions : 
OpenGL ES profile version string: OpenGL ES 3.2 Mesa 17.3.3 
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20 
OpenGL ES profile extensions:

核心配置文件的 OpenGL 版本字符串和 GLSL 版本字符串都是 4.5。但是,它也显示 OpenGL 版本字符串为3.0,GLSL 版本字符串为1.3. 为了使用我自己的着色器,版本必须至少为3.3。我尝试在着色器的开头使用#version 330 core,但是当我运行我的程序时,出现了以下error message

Cannot compile vertex shader. 
ERROR: Cannot compile shader. 
OpenGL Version: 3.0 Mesa 17.3.3 
0:4(10): error: GLSL 3.30 is not supported. Supported versions are: 1.10, 1.20, 1.30, 1.00 ES, 3.00 ES, 3.10 ES, and 3.20 ES 

貌似程序用的是OpenGL 3.0而不是4.5,我上网查了一下,有人说OpenGL 4.5 is only available if requested at context creation because compatibility contexts are not supportedMesa的release note里,根据this post.

如何在创建上下文时创建核心配置文件或请求,以便在我的程序中使用 OpenGL 4.5?

我在 Linux 操作系统上使用 Eclipse 作为我的 C++ 开发 IDE(我使用的这个特定发行版是 PCLinuxOS)。

【问题讨论】:

    标签: c++ eclipse opengl glut freeglut


    【解决方案1】:

    使用glutInitContextVersion()glutInitContextProfile() 选择所需的上下文版本和上下文配置文件:

    ...
    glutInit( ... );
    glutInitContextVersion( 3, 3 );
    glutInitContextProfile( GLUT_CORE_PROFILE );
    glutInitDisplayMode( ... );
    glutCreateWindow( ... );
    ...
    

    Documentation? What documentation?

    【讨论】:

    • 这立即解决了问题。非常感谢!
    猜你喜欢
    • 2014-06-03
    • 1970-01-01
    • 1970-01-01
    • 2019-07-20
    • 2018-12-31
    • 1970-01-01
    • 2017-01-07
    • 1970-01-01
    相关资源
    最近更新 更多