I'm trying to compile GLSL shaders for use in LWJGL with OpenGL. I'm on macOS Sierra.
I get the following error when trying to compile the shaders:
ERROR: 0:1: '' : version '400' is not supported
ERROR: 0:1: '' : syntax error: #version
The shader code works on Windows, but when testing on macOS it doesn't. Here's the shader code:
#version 400 core
in vec3 position;
in vec2 textureCoords;
out vec2 pass_textureCoords;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
void main(void)
{
gl_Position = projectionMatrix * viewMatrix * vec4(position, 1.0);
pass_textureCoords = textureCoords;
}
Here is how i'm loading the shader...
private static int loadShader(String file, int type) throws IOException {
StringBuilder shaderSource = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(
ShaderProgram.class.getClassLoader().getResourceAsStream("shaders/" + file))
)) {
String line;
while ((line = reader.readLine()) != null) {
shaderSource.append(line).append('\n');
}
System.out.println(shaderSource.toString());
int shaderID = GL20.glCreateShader(type);
GL20.glShaderSource(shaderID, shaderSource);
GL20.glCompileShader(shaderID);
if (GL20.glGetShaderi(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
System.out.println(GL20.glGetShaderInfoLog(shaderID, 500));
System.err.println("Error compiling shader " + file);
System.exit(-1);
}
return shaderID;
}
}
The print statement returns the correct output, yet it still gives me the error.
I've searched all over stackoverflow for a solution, yet everyone says that they're compiling it without line breaks, which i have. I'm confused as to why this is occurring.