问题
I'm working on a project that utilizes freeglut
and GLEW
. In order to use the vertex and fragment shaders in my program, the minimum OpenGL version I need to use is 3.3
. I have checked the OpenGL version and GLSL version and this is the result:
[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:
The OpenGL version string as well as GLSL version string for core profile is both 4.5
. However, it also shows that OpenGL version string is 3.0
and the GLSL version string is 1.3.
In order to use my own shaders, the version has to be 3.3
minimum. I tried to use #version 330 core
at the beginning of my shader but when I run my program the following error message appeared:
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
It seems that the program is using OpenGL 3.0 instead of 4.5, I have looked up online and someone said that OpenGL 4.5 is only available if requested at context creation because compatibility contexts are not supported
was in the release note of Mesa
, according to this post.
How can I create a core profile or request at context creation so I can use OpenGL 4.5 in my program?
I'm using Eclipse as my C++ development IDE on Linux operating system (This specific distro I'm using is PCLinuxOS).
回答1:
Use glutInitContextVersion()
and glutInitContextProfile()
select the context version and context profile you want:
...
glutInit( ... );
glutInitContextVersion( 3, 3 );
glutInitContextProfile( GLUT_CORE_PROFILE );
glutInitDisplayMode( ... );
glutCreateWindow( ... );
...
Documentation? What documentation?
来源:https://stackoverflow.com/questions/48472285/create-core-context-with-glut-freeglut