简体   繁体   中英

Error compiling GLSL shader in linux

I recently wrote a basic rendering engine using OpenGL on my Windows machine, everything runs fine on that end. Unfortunately when I attempted to bring it over onto my laptop which is running Ubuntu 12.04 there were some complications, initially the linking settings and libraries were the problem but I managed to sort all that out, my current problem is with compiling the GLSL shaders, when I compile both the vertex and fragment shaders I get the following error.

'0:2(14): preprocessor error: syntax error, unexpected IDENTIFIER, expecting NEWLINE
'

This is the code from my vertex shader.

#version 330 core

layout(location = 0) in vec3 position;
layout(location = 1) in vec2 uv;
layout(location = 2) in vec3 normal;

struct DirectionalLight{
    vec3 direction;
    vec3 color;
    vec3 ambient;
};

uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;
uniform DirectionalLight dLight;

out vec2 iUv;
out vec3 iPosition;
out vec3 iNormal;
out vec3 lightDir;

void main()
{
    iUv = uv;
    iPosition = vec3(viewMatrix * modelMatrix * vec4(position,1));
    iNormal = normal;
    lightDir = vec3(normalize(viewMatrix * vec4(dLight.direction, 0)));

    gl_Position =  projectionMatrix * viewMatrix * modelMatrix * vec4(position,1);
}

Any ideas?

  1. Try to add more new blank lines at the end of your shader program.
  2. Try to use a text editor(Ubuntu) to create a new copy of your code.

In my case changing

#version 330 core

to

#version 330

helped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM