Results 1 to 4 of 4

Thread: shader could not compile

  1. #1
    Newbie Newbie
    Join Date
    Nov 2013

    shader could not compile

    Hi there I am a beginner to OpenGL and had been trying to write a program that displays a few basic shapes on the screen but somehow only a window without the expected shapes showed up. After tracing it I realised the vertex shader and fragment shader failed to compile. Any help? much appreciated!

    Here's my shader source:
    Code :
    const GLchar* vertexSource =
    "#version 150 core\n"
    "in vec3 position;"
    "void main() {"
    "   gl_Position = vec4(position, 1.0);"
    const GLchar* fragmentSource =
    "#version 150 core\n"
    "out vec4 outColor;"
    "void main() {"
    "   outColor = vec4(1.0, 1.0, 1.0, 1.0);"

    and here's how I create and compile the shaders
    Code :
    GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(vertexShader, 1, &vertexSource, NULL);
    GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(fragmentShader, 1, &fragmentSource, NULL);

  2. #2
    Senior Member Regular Contributor malexander's Avatar
    Join Date
    Aug 2009
    Try putting more newlines at the end of each line in the string. If that doesn't work, fetch the compile logs for each of the shaders with

    Code :
    int log_len = 0;
    glGetShaderiv(vertShader, GL_INFO_LOG_LENGTH, &log_len);
    char *log_text = new char[log_len+1];
    glGetShaderInfoLog(vertShader, log_len, &log_len, log_text);

  3. #3
    Newbie Newbie
    Join Date
    Nov 2013
    Hi malexander,

    Thanks for the reply, I had altered my code to reading in the shaders glsl file instead, and checked using the compile log, it gives the error message:

    ERROR: 0:2: '' : syntax error #version
    I had done a lot of searches online and many had said that this problem is caused by the shader source having no null-terminator in the end. so I had tried to add a null terminator like this

    Code :
        std::string VertexShaderCode;
        std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
            std::string Line = "";
            while(getline(VertexShaderStream, Line))
                VertexShaderCode += "\n" + Line;
            VertexShaderCode += "\0"; //<-- (THE ADDED LINE FOR NULL TERMINATOR)

    but it still give me the same error. Any ideas?


  4. #4
    Senior Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Quote Originally Posted by scoder View Post
    Any ideas?
    printf("%s %s %s\n", glGetString(GL_RENDERER), glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION));

Similar Threads

  1. Can't compile shader anymore
    By _misq in forum OpenGL: GLSL
    Replies: 8
    Last Post: 07-07-2011, 05:56 PM
  2. JVM won't die after shader compile
    By Jeffg in forum OpenGL: GLSL
    Replies: 10
    Last Post: 11-19-2010, 07:24 AM
  3. Shader Compile Error
    By adamnation in forum OpenGL: GLSL
    Replies: 6
    Last Post: 06-05-2005, 12:38 PM
  4. compile shader glsl
    By ac in forum OpenGL: GLSL
    Replies: 5
    Last Post: 08-17-2004, 08:30 PM
  5. Conditional shader compile
    By Zengar in forum OpenGL: GLSL
    Replies: 2
    Last Post: 02-20-2004, 01:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean