Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 13

Thread: Shader Compile Error: ERROR: 0:1: '' : syntax error #version

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2011
    Posts
    26

    Shader Compile Error: ERROR: 0:1: '' : syntax error #version

    Hello,

    I am trying to compile a very simple vertex shader and I got this error, however I don't see anything wrong in my vertex shader. This is the error that I get:

    Code :
    ERROR: 0:1: '' : syntax error #version

    This is what my shader looks like:

    Code :
    #version 150
     
    in vec2 position;
     
     
    void main()
    {
        gl_Position = vec4( position, 0.0, 1.0 );
    }

    Am I missing something here? As far as I can tell there isn't anything wrong with my shader.

    If it matters: I am using the OpenGL 3.2 Core Profile on OS X 10.8.4 using Xcode 4.6.3 as my IDE with glfw as my windowing system for this program.

    Thanks!

  2. #2
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    495
    Quote Originally Posted by Blakeasd View Post
    I am trying to compile a very simple vertex shader and I got this error
    Quote Originally Posted by Blakeasd View Post
    This is what my shader looks like:
    You don't show the code you're using to compile it.

    If you're trying to compile it using the IDE, you need to read a tutorial on how to use shaders.

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2011
    Posts
    26
    Thanks for the response. Here is my code to load and compile the shaders:

    Code :
     std::ifstream vertexShaderFile;
        std::string tempString;
        std::string vertexShaderString;
     
        vertexShaderFile.open("VertexShader.glsl");
     
        if(vertexShaderFile.is_open()){
        while (getline(vertexShaderFile, tempString)) {
            vertexShaderString = vertexShaderString + tempString;
        }
        }else{
     
            std::cout << "The vertex shader file is closed" << std::endl;
            exit(1);
        }
     
        std::ifstream fragmentShaderFile;
        std::string tempString2;
        std::string fragmentShaderString;
     
        fragmentShaderFile.open("FragmentShader.glsl");
     
        if (fragmentShaderFile.is_open()) {
            while (getline(fragmentShaderFile, tempString2)) {
                fragmentShaderString = fragmentShaderString +  tempString2;
            }
        }else{
            std::cout << "The fragment shader file is closed" << std::endl;
            exit(1);
        }
     
     
        const char* vertexShaderCString = vertexShaderString.c_str();
        const char* fragmentShaderCString = fragmentShaderString.c_str();
     
        GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
        glShaderSource(vertexShader, 1, &vertexShaderCString, NULL);
        glCompileShader(vertexShader);
     
        GLint status;
        glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &status);
     
        if(status == GL_FALSE){
     
            std::cout << "The vertex shader was compiled with an error(s)." << std::endl;
            char buffer[512];
            glGetShaderInfoLog(vertexShader, 512, NULL , buffer);
            std::cout << buffer << std::endl;
        }

    Hopefully this will provide more clues.

    Thanks!

  4. #4
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    It really amazes me just how few C++ programmers know something as simple as how to read a text file with iostreams. It's really not that difficult, and the fact that you were reading it line-by-line should have been a tip-off that you were doing it wrong.

    Really, have you ever seen a programming language where line-by-line was the way you had to read a text file?

    In any case, your code is wrong because std::getline doesn't actually put the endline character in the string. So you're sticking every statement on a single line, which never works.

  5. #5
    Junior Member Newbie
    Join Date
    Sep 2011
    Posts
    26
    Thanks for the reply, but now I have a different problem. Sometimes the shader will compile, but other times it won't compile and I'll get seemingly random shader compilation errors.

    Here my new code that loads and compiles the vertex shader:

    Code :
         std::ifstream vertexShaderFile("VertexShader.glsl", std::ios::in | std::ios::binary | std::ios::ate);
     
        if (vertexShaderFile.is_open()) {
            long size;
            size = vertexShaderFile.tellg();
            char *vertexShaderCString = new char [size];
            vertexShaderFile.seekg(0, std::ios::beg);
            vertexShaderFile.read(vertexShaderCString, size);
     
            const char *vertexShaderCStringConst = vertexShaderCString;
     
            GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
            glShaderSource(vertexShader, 1, &vertexShaderCStringConst, NULL);
            glCompileShader(vertexShader);
     
            GLint status;
            glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &status);
     
            if (status == GL_TRUE) {
                std::cout << "Vertex Shader compiling went OK" << std::endl;
            }
     
            char buffer[512];
            glGetShaderInfoLog(vertexShader, 512, NULL,buffer);
            printf("%s",buffer);
     
        }

    The error message changes each time, the last one I got was this:

    Code :
    ERROR 0.8 'P' : error syntax error

    Any help is appreciated!
    Thanks!

  6. #6
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    That's my fault for linking you to buggy code; I should have looked at the first example more closely. I have since fixed it over on Stack Overflow.

    Though the memory leak you wrote in when you copy-and-pasted the buggy code is your fault. I was kinda hoping that you'd use one of the other alternatives, rather than the one that directly allocates memory for no adequately explained reason.

  7. #7
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    495
    Quote Originally Posted by Alfonse Reinheart View Post
    It really amazes me just how few C++ programmers know something as simple as how to read a text file with iostreams. It's really not that difficult, and the fact that you were reading it line-by-line should have been a tip-off that you were doing it wrong.
    While probably less efficient than the linked version, using a stringbuf is simpler and more robust (e.g. it works with streams which don't support seeking, such as pipes and sockets):
    Code :
    std::string read(std::istream& s)
    {
        std::stringbuf buf(std::ios::out);
        s >> &buf;
        return buf.str();
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •