View Full Version : what values to use to compile shaders?

06-15-2013, 11:05 AM
hi all. im having trouble compiling my shaders. here is what i believe to be the relevant code.

static const char *vshader =
"#version 430 core"
"layout (location = 0) in vec4 vPosition;"
"void main()"
" gl_Position = vPosition;"

static const char *fshader =
"#version 430 core"
"out vec4 fcolor;"
"void main()"
" fColor = vec4 (0.0, 0.0, 1.0, 1.0);"

GLuint prog = glCreateProgram();
GLuint vert = glCreateShader(GL_VERTEX_SHADER);
GLuint frag = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(vert, 1, &vshader, 0);
glShaderSource(frag, 1, &fshader, 0);
glAttachShader(prog, vert);
glAttachShader(prog, frag);

i believe the problem is with glShaderSource(). i dont know what values to use.
thanks for the help.

06-15-2013, 01:55 PM
You should check if the shader compiled with glGetShader(shader_id, GL_COMPILE_STATUS, &status), and the errors/warnings of the compiles with glGetShaderInfoLog(). You can check the link status with glGetProgram(program_id, GL_LINK_STATUS, &status), and the link errors/warnings with glGetProgramInfoLog().

The reason it's not working is that you've spelled fcolor two different ways in the fragment shader.

06-15-2013, 04:58 PM
More significantly, you need some newline characters. When C concatenates adjacent string literals, it doesn't insert newlines (or any other whitespace).

At a minimum, the #version directive needs to be terminated with a newline. At the moment, the "core" at the end of the first line and the "layout" at the beginning of the second line will be combined into a single "corelayout" token.

I don't think that you need any other newlines in this particular case, but more complex shaders will have problems (e.g. a "//" comment will extend to the end of the shader, not the end of a single string literal).