I am using LWJGL to create an OpenGL context. I can get it running on my machine (OpenGL 4.2 compatible) and with changes to the simple shaders also on OpenGL 2.1. I have to write code (the shaders, or rather the linking and compilation of them, seem to be the problem here) that is compatible with OpenGL 2.1. I assumed it would be easy to just write:
The Frag shader:
#version 120
in vec4 pass_Color;
out vec4 out_Color;
void main(void) {
out_Color = pass_Color;
}
The Vert shader:
#version 120
in vec4 in_Position;
in vec4 in_Color;
out vec4 pass_Color;
uniform mat4 Model;
uniform mat4 View;
uniform mat4 Projection;
void main(void) {
gl_Position = Projection * View * Model * in_Position;
pass_Color = in_Color;
}
as the first line of my shaders and call it a day. However, on one machine with a OpenGL 3.3 supporting graphics card, those shaders would not link and compile. When changed to
#version 330
// - or even -
#version 150
they do link and compile. I have read about compatibility, core and forward compatibility and as I understand it, the problem could be that GLSL 1.20 is not supported on the OpenGL 3.3 machine unless it is instructed in the code to run a compatibility context (I may be phrasing it wrongly, please correct me). But I worry, since 2.1 does not know about OpenGL profiles, surely I will need to do some checks before attempting to setup the context with one.
Even if this is the case, I am not entirely sure how to do the correct logic to ensure that both machines with graphics cards limited to OpenGL 2.1 (and corresponding GLSL version) and machines with much later versions (3.3, 4.2, etc.) will accept it as well (using the LWJGL).
Please note that I would like to keep the code as "modern OpenGL" as possible.
Try specifying ogl version like this:
From here.