OpenGL, how to set up GLSL version?
Asked Answered
J

1

6

My system's default version for OpenGL and GLSL using freeglut is 4.1, also using glew there is no problem with its initialization, shader compilation and linking, and execution.

This default version happens when I don't specify glutInitContextVersion, glutInitContextFlags or glutInitContextProfile, then my shaders work correct.

Regardless I have support to this version, I would like to provide a 3.3 alternative. When I use the glut context specifying the 3.3 version, the application starts with no errors, glew doesn't complain. My shaders are suppose to use the GLSL 3.3 version, then I set the line

#version 330

But when my shaders are compiled, OpenGL complains with an invalid enumerant message. I tried removing this line or setting it to another version but I still get the same error. After all initialization has been properly done, i ask for the OpenGL version and I get the right 3.3, but for the GLSL version am still getting the default 4.1.

glGetString(GL_SHADING_LANGUAGE_VERSION);

Please correct me if am right, I guess this version is overwritten by the version line in the shaders code. I wonder if there is a chance to initialize the context specifying the GLSL version too?

Jeroboam answered 16/11, 2011 at 19:37 Comment(5)
Where does the invalid enum error originate? Run your program under gDEBugger or something.Rupiah
Right after calling the glCreateShader(GL_VERTEX_SHADER); Couldn't that be I need to use the macros GL_ARB_vertex_shader or GL_ARB_fragment_shader? But am sure 3.3 version supports the GL_VERTEX_SHADER. Will run the gDEBugger meanwhile.Jeroboam
gDEBugger is a great tool, can't find a good way to pin point the problem yet. But I manage to make it work specifying a previous OpenGL 3.1. This works; compiles, links and executes the shaders. It refuses to work with the 3.3, why could that be?Jeroboam
At least I know my video card supports version from 3.0 to 3.3, i run the OpenGL Extension Viewer 4.0 and successfully tested the versions. Although am not sure if this test is enough to know if there is a problem with my driver version. Most likely it is an initialization problem with the glut context.Jeroboam
@Jeroboam Instead of 'edit: I solved it etc.', the custom on StackOverflow is to answer your own question, and accept that answer.Vella
J
1

I finally solved it. If I set the core profile along with the compatibility mode

glutInitContextProfile(GLUT_CORE_PROFILE | GLUT_COMPATIBILITY_PROFILE);

OpenGL commands from 2.1 version won't be recognized. This goes against the information provided in the tutorials. Anyways by only setting the GLUT_COMPATIBILITY_PROFILE it works, using 3.3 or greater version.

Jeroboam answered 5/10, 2020 at 20:34 Comment(1)
Note that on some systems, if you ask for a compatibility profile you will be limited to an older version of OpenGL. This doesn’t apply to AMD or Nvidia drivers on Windows or Linux, but it does apply to Mesa on Linux and it applies to OpenGL on macOS.Endurance

© 2022 - 2024 — McMap. All rights reserved.