I'm just starting out with OpenGL on Linux. In order to write future-proof code, I explicitly wrote code for OpenGL 4.0 Core Profile in the first place, thus the shaders are GLSL 4.0.
That worked fine on a recent notebook with an AMD graphics card using the fglrx driver, which supports OpenGL 4.0. I then tried to run this code on another box with an Intel card, whose driver only supports OpenGL 2.1. That failed, obviously.
I then rewrote the shaders in GLSL 1.20, without changing the C++ code at all. Now it works on the Intel box, but on the AMD notebook, it displays nothing (except for glClearColor).
That confuses me. The code checks glGetError() periodically, so an error in the shader compilation would have been caught.
My only idea would have been that I accidentally created a GL 4 core context (instead of a compatibility context) on the AMD box, but the context is created by SDL 1.2, which (says the documentation) can create compatiblity contexts only.
Can anyone see what the problem is, or give hints on how to debug this? For reference, I'm attaching all shaders. (They're pretty trivial; as I said, I'm just starting.)
#version 120 (vertex shader)
uniform mat4 ModelMatrix;
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
attribute vec4 in_Color;
attribute vec4 in_Position;
varying vec4 pass_Color;
void main(void) {
gl_Position = (ProjectionMatrix * ViewMatrix * ModelMatrix) * in_Position;
pass_Color = in_Color;
}
#version 400 (vertex shader)
layout(location=0) in vec4 in_Position;
layout(location=1) in vec4 in_Color;
out vec4 ex_Color;
uniform mat4 ModelMatrix;
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
void main(void) {
gl_Position = (ProjectionMatrix * ViewMatrix * ModelMatrix) * in_Position;
ex_Color = in_Color;
}
#version 120 (fragment shader)
varying vec4 pass_Color;
void main(void) {
gl_FragColor = pass_Color;
}
#version 400 (fragment shader)
in vec4 ex_Color;
out vec4 out_Color;
void main(void) {
out_Color = ex_Color;
}
glGetError
. The OpenGL wiki has information on how to properly catch compilation errors. There's even a bit of example code for you to follow. \$\endgroup\$