Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GLSL Unsupported Version

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.

like image 653
Erouax Avatar asked Aug 13 '26 13:08

Erouax


1 Answers

Hello not an java expert here, i did some experiments using JOGL, so maybe i cant give you a hint to work in the right direction.

An issue with new line on MAC How to append a newline to StringBuilder

Second:

https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.4.00.pdf

The #version directive must occur in a shader before anything else, except for comments and white space.

This is what is looks like RAW in JOGL you see the newline is needed is after the version directive , everthing else has an semicolons as statement separators.

  // 
  // create fragment Shader
  int fragShader = gl4.glCreateShader(GL4.GL_FRAGMENT_SHADER);
  gl4.glShaderSource(fragShader, 1, 
    new String[]{"#version 420 \n"
    +"out vec4 fragColor;"
    +"void main(void) {"
    +"fragColor = vec4(0.2, 0.2, 0.5, 1.0);}" }, null);
    gl4.glCompileShader(fragShader);
like image 189
nabr Avatar answered Aug 15 '26 04:08

nabr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!