GLSL Linker errors

I have been working on using OpenGL, and now that I finally have it working the shaders decided to die on me. The program starts as it should and renders a dark-grey background (the one I set it to) but never draws my triangle (which I made in another function and is calling in the render loop). So I looked through my log file and found out the shaders did not link. I don't know how to get the linker errors so it would be helpful if someone could give me a tip.

Here is the shader compilation-linking process:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
char *Shaders::textFileRead(char *fn) 
{
	FILE *fp;
	char *content = NULL;
	
	int count=0;

	if (fn != NULL) 
	{
		fp = fopen(fn,"rt");

		if (fp != NULL) 
		{

			fseek(fp, 0, SEEK_END);
			count = ftell(fp);
			rewind(fp);
				
			if (count > 0) 
			{
				content = (char *)malloc(sizeof(char) * (count+1));
				count = fread(content,sizeof(char),count,fp);
				content[count] = '\0';
			}
			fclose(fp);
		}
	}

	return content;
}

GLuint Shaders::loadBasicShaders()
{
	log->logMessage(log->GL, "Creating basic shaders...");
	GLint compile_ok = GL_FALSE, link_ok = GL_FALSE;
	GLuint vs = glCreateShader(GL_VERTEX_SHADER);
	const char* vSource = textFileRead("../Shaders/basicShader.vert");
	glShaderSource(vs, 1, &vSource, NULL);
	glCompileShader(vs);
	glGetShaderiv(vs, GL_COMPILE_STATUS, &compile_ok);
	if (0 == compile_ok)
	{
		log->logMessage(log->GLERR, "Error in vertex shader\n");
		return false;
	}

	GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
	const char* fSource = textFileRead("../Shaders/basicShader.frag");
	glShaderSource(fs, 1, &fSource, NULL);
	glCompileShader(fs);
	glGetShaderiv(fs, GL_COMPILE_STATUS, &compile_ok);
	if (!compile_ok) 
	{
		log->logMessage(log->GLERR, "Error in fragment shader");
		return false;
	}

	glAttachShader(program, vs);
	glAttachShader(program, fs);
	glLinkProgram(program);
	glGetProgramiv(program, GL_LINK_STATUS, &link_ok);
	if (!link_ok) {
		log->logMessage(log->GLERR, "Could not link basic shaders!");
		return false;
	}
	log->logMessage(log->GL, "Done!");
	return program;
}


The shaders seem to compile but won't link.

Vertex shader:
1
2
3
4
5
6
7
8
#version 150

in vec4 a_vertex;

void main(void)
{
	gl_Position = a_vertex;
}


Fragment shader
1
2
3
4
5
6
#version 150
out vec4 MyFragColor;
void main(void)
{
    MyFragColor = vec4(1.0, 0.0, 0.0, 1.0);
}


I am using OpenGL 3.2 and an AMD Radeon 6870 with the latest drivers.

Thanks in advance!
Last edited on
*bump*
closed account (o1vk4iN6)
I haven't kept up with glsl, but from what I can tell it doesn't make sense to have "out" in the fragment shader. If you want to set a color you would have to assign it to gl_FragColor if it is still the same in 3.2. How else would it know to set what ?

You can also view the compile errors, little bit of google can easily find you some code.
Last edited on
Thanks for the reply, i actually just copied those shaders over from a tutorial ( i am completely un-educated on GLSL ) So i kind of just assumed it would work. But i had no compiler errors on my Shaders.
Topic archived. No new replies allowed.