StackExchange!
I've been working with opengl for a bit and I'm trying to finally load the shaders instead of having them inline. I'm having a ton of issues, though. As soon as I solve one, another pops up. Now, the issue is glGetProgramInfoLog reporting "Fragment Shader output type error." I thought it might be caused by the old graphics card - Intel Graphics 300, but it was working when it was inline (directly as a const char *). Does anyone know what this might mean, and how to solve this? Thanks in advance!
Vertex Shader:
#version 400 compatibility
layout (location = 0) in vec3 vertexPosition;
uniform mat4 Model;
uniform mat4 View;
uniform mat4 Projection;
void main () {
gl_Position = Projection * View * Model * vec4(vertexPosition, 1.0);
}
Fragment Shader:
#version 330
layout(location = 0) out vec4 fragColor;
void main()
{
fragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
Shader Loading Code:
GLuint getShaders(const char *vertexpath, const char *fragmentpath) {
printf("****************** Loading Shaders ******************\nVertex: %s\nFragment: %s\n\n", vertexpath, fragmentpath);
std::string VertexShaderCode;
std::ifstream VertexShaderStream(vertexpath, std::ios::in);
if (VertexShaderStream.is_open()){
std::string Line = "";
while (getline(VertexShaderStream, Line))
VertexShaderCode += "\n" + Line;
VertexShaderStream.close();
}
else{
printf("Impossible to open %s. Are you in the right directory ? Don't forget to read the FAQ !\n", vertexpath);
getchar();
return 0;
}
std::string FragShaderCode;
std::ifstream FragShaderStream(fragmentpath, std::ios::in);
if (FragShaderStream.is_open()){
std::string Line = "";
while (getline(FragShaderStream, Line))
FragShaderCode += "\n" + Line;
FragShaderStream.close();
}
GLuint vs = glCreateShader(GL_VERTEX_SHADER);
char const * VertexSourcePointer = VertexShaderCode.c_str();
glShaderSource(vs, 1, &VertexSourcePointer, NULL);
glCompileShader(vs);
GLint logSize = 0;
glGetShaderiv(vs, GL_INFO_LOG_LENGTH, &logSize);
printf("Size: %i\n", logSize);
GLint isCompiled = 0;
glGetShaderiv(vs, GL_COMPILE_STATUS, &isCompiled);
if (isCompiled == GL_FALSE) {
GLint maxLength = 0;
glGetShaderiv(vs, GL_INFO_LOG_LENGTH, &maxLength);
// The maxLength includes the NULL character
std::vector<GLchar> errorLog(maxLength);
glGetShaderInfoLog(vs, maxLength, &maxLength, &errorLog[0]);
printf("Vertex Shader Error Report:\nSize: %i\n%s\n----------------------------\n", logSize, errorLog);
// Exit with failure.
glDeleteShader(vs); // Don't leak the shader.
return 0;
}
GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
char const * FragSourcePointer = FragShaderCode.c_str();
glShaderSource(fs, 1, &FragSourcePointer, NULL);
glCompileShader(fs);
logSize = 0;
std::string shaderInfo;
glGetShaderiv(fs, GL_INFO_LOG_LENGTH, &logSize);
printf("Size: %i\n", logSize);
isCompiled = 0;
glGetShaderiv(fs, GL_COMPILE_STATUS, &isCompiled);
if (isCompiled == GL_FALSE) {
GLint maxLength = 0;
glGetShaderiv(fs, GL_INFO_LOG_LENGTH, &maxLength);
// The maxLength includes the NULL character
std::vector<GLchar> errorLog(maxLength);
glGetShaderInfoLog(fs, maxLength, &maxLength, &errorLog[0]);
printf("Fragment Shader Error Report:\nSize: %i\n%s\n----------------------------\n", logSize, errorLog);
// Exit with failure.
glDeleteShader(fs); // Don't leak the shader.
return 0;
}
GLuint program = glCreateProgram();
glAttachShader(program, fs);
glAttachShader(program, vs);
glLinkProgram(program);
GLint isLinked = 0;
glGetProgramiv(program, GL_LINK_STATUS, &isLinked);
if (isLinked == GL_FALSE) {
GLint maxLength = 0;
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &maxLength);
//The maxLength includes the NULL character
std::vector<GLchar> infoLog(maxLength);
glGetProgramInfoLog(program, maxLength, &maxLength, &infoLog[0]);
//The program is useless now. So delete it.
glDeleteProgram(program);
printf("Program Error Report:\n%s\n----------------------------\n", infoLog);
return 0;
}
glDeleteShader(vs);
glDeleteShader(fs);
return program;
}
layout
method of color output and tried settinggl_FragColor
instead? \$\endgroup\$