use of uniform sampler2D in frag shader

I have an issue where my frag shader compiles and attaches without error, but then the glLinkProgram for the program fails, based on the presence of this line:

uniform sampler2D TexMap;

Nb, TexMap is not used yet. If I change “sampler2D” to float, the program links.

Do I have to set a specific min version to use uniform samplers?

To the best of my knowledge, no. What is the linker error? What does the rest of the shader look like? What if you do use TexMap in the shader? Do you still get the error?


Nb, TexMap is not used yet.

Then why is it in your program? And what error message are you getting?

I had intended to use it – I commented the usage out, in fact to see if that would change anything, to no avail.

I’ve fooled around a bit since then and altho I would swear it was just the presence of that variable before (since switching it to a float and removing the usage worked), now it hinges more on it’s use:

uniform sampler2D TexMap;

void main() {
//	gl_FragColor = gl_Color*texture2D(TexMap,gl_TexCoord[0].st);
	gl_FragColor = vec4(0.8,0.8,0.8,1.0);

Ie, commenting that line out makes it work. Now, I don’t understand the line very well, I just copied it out of the red book (7th ed, example 15-8) BUT at this point the shader 1) has not been used, 2) compiled without error, and AFAICT this is just intended to “provide the same results as using GL_MODULATE”.

I’m not getting any kind of error at this point – I noticed it because subsequently I get an INVALID_OPERTATION using the shader, which I traced it back to the linker failing. Here’s the bailout:

	Shaders[2] = glCreateProgram();
	glGetProgramiv(Shaders[2],GL_LINK_STATUS, &err);
	if (err == GL_FALSE) {
		fprintf(stderr, "glLinkProgram() failed %u
", Shaders[2]);
		while ((err=glGetError()) != GL_NO_ERROR) reportError(err);
		return -1;

Again, if this exits, it does not report anything other than the bad linkage.

Use glGetProgram instead of glGetError to get the link failure details. Here is an example (in C#, sorry):

GL.GetProgram(_program, ProgramParameter.LinkStatus, out linkStatus);


gl_FragColor = gl_Color*texture2D(TexMap,gl_TexCoord[0].st);

is indeed a GL_MODULATE modulate example. texture2D reads a color from the 2D texture bound to the texture unit defined by TexMap. The texel is addressed by gl_TexCoord[0].st (ignoring filtering). The color read from the texture is multiplied (e.g. modulated) with the input color from the previous stage (e.g. you may have used glColor or defined per-vertex colors).