I'm using xcode to make a game with OpenGL. I have used GLUT to initialise a window. I have shaders that I wish to implement but when I try to compile them, I get two compile errors in the info log. My shaders look like this:
//FirstShader.vsh
#version 150 core
in vec3 position;
void main()
{
gl_Position = vec4(position, 1.0);
}
//FirstShader.fsh
#version 150 core
out vec4 fragData;
void main()
{
fragData = vec4(0.0, 0.0, 1.0, 1.0);
}
I'm reading the file and compiling it with this code:
GLuint createShaderFromFile(const GLchar *path, GLenum shaderType){
GLuint shaderID = glCreateShader(shaderType);
std::ifstream fin;
fin.open(path);
if(!fin.is_open()){
fin.close();
std::cout << "Shader Not Found" << std:: endl;
return 0;
}
std::string source((std::istreambuf_iterator<GLchar>(fin)),std::istreambuf_iterator<GLchar> ());
fin.close();
const GLchar* shaderSource = source.c_str();
glShaderSource(shaderID, 1, &shaderSource, NULL);
glCompileShader(shaderID);
GLint compileStatus;
glGetShaderiv(shaderID, GL_COMPILE_STATUS, &compileStatus);
if (compileStatus != GL_TRUE) {
std::cout << "Shader failed to compile" << std::endl;
GLint infoLoglength;
glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &infoLoglength);
GLchar* infoLog = new GLchar[infoLoglength + 1];
glGetShaderInfoLog(shaderID, infoLoglength, NULL, infoLog);
std::cout << infoLog << std::endl;
delete infoLog;
return 0;
}
return shaderID;
}
Im getting these errors:
ERROR: 0:1: '' : version '150' is not supported
ERROR: 0:1: '' : syntax error #version
My OpenGL version is 2.1 and my glsl version is 1.20. Does anybody know how I can fix this?