Take the 2-minute tour ×

I'm trying to get my cross-platform shader to compile a default shader which is nothing more than the basic shader program like so:

Vertex program:

void main()
    //vec4 vertex = matModelView * a_vertex;
    gl_Position = ftransform();//matProj * vertex;

    gl_TexCoord[0] = gl_MultiTexCoord0;

Fragment program:

uniform sampler2D colorMap;

void main()
    gl_FragColor = texture2D(colorMap, gl_TexCoord[0].st);

I am aware that the gl_ prefix are deprecated functions but this is just a default shader so I know everything works. This sample works fine under windows with my shader class.

Now onto my shader class, when I create a Shader object I call the load method which takes a path without a file extension. For example: ./data/shaders/default The loader takes this and searches for that string + .vert .geom or .frag for the appropriate shader programs. These are then loaded and passed to the OpenGL part of creating the programs. This is where something seems to go wrong, I can confirm that the content of the shader programs is correctly loaded from disk so this is not where the problem lies as far as I can see.

When the file is loaded it goes onto compiling the vertex and fragment programs (or geometry but this is optional):

a_Type is either GL_FRAGMENT_SHADER or GL_VERTEX_SHADER. a_Source is the content of the shader program file (the .vert/.frag/.geom file). When I load the vertex program the compilation instantly fails and if( success != GL_TRUE ) is hit and evaluated as being so and I get a compilation error. I don get any output whatsoever, the "Shader compile output" printf doesn't print any info about compilation. (The OGLCHECK is a macro which checks the opengl error stack, this doesn't show anything either.)

GLuint Shader::Compile(const GLuint a_Type, const char* a_Source)
    if(a_Source == NULL)
        return 0;

    GLuint handle = glCreateShader(a_Type); OGLCHECK
    glShaderSource(handle, 1, &a_Source, NULL); OGLCHECK
    glCompileShader(handle); OGLCHECK

    int bufflen = 0;
    GLint success = GL_FALSE;

    glGetShaderiv(handle, GL_INFO_LOG_LENGTH, &bufflen); OGLCHECK
    if(bufflen > 1)
        GLchar* logString = new GLchar[bufflen + 1];
        glGetShaderInfoLog(handle, bufflen, 0, logString); OGLCHECK
        printf( "Shader compile output:\n%s\n", logString );

        delete logString;
        logString = 0;

    glGetShaderiv(handle, GL_COMPILE_STATUS, &success); OGLCHECK
    if(success != GL_TRUE)
        printf( "Failed to compile shader!\n" );

        glDeleteShader(handle); OGLCHECK
        handle = 0;

    return handle;

I'm unsure whats going on, this implementation works fine under windows as this is part of my rendering engine which I've ported to linux. Anyone had similar problems regarding shader compilation under linux?

Also, I've checked glxinfo, here's some info:

glxinfo | grep "OpenGL version"
OpenGL version string: 4.2.0 NVIDIA 295.49

I also grep'd on fragment_program, vertex_program, geometry_program and all these extension seem to be available. I'm running Ubuntu 12.04.

Update: It seems its unrelated to the shaders files but something else, when I run it from a terminal its fine it compiles the shaders and uses them but whenever I run it from Code::Blocks it just fails to compile the shaders.. they are being loaded and passed to OpenGL. No clue whats going on.

share|improve this question
Maybe DOS newline vs. Unix newline? DOS encodes newlines as a \r\n pair, wheras Unix encodes just n. By specification both are whitespace and the compiler should accept it, but maybe it chews up on that. –  datenwolf Jul 24 '12 at 13:51
Are you using the GL3.1+ Core Profile or just the compatibility profile on Windows and 3.1+ on linux ? If so, the shaders are non-standard on linux - you have to declare the out_FragColor elements manually –  Viktor Latypov Jul 24 '12 at 14:00
@datenwolf Checked, same result but thanks for the tip. –  Yonathan Jul 24 '12 at 15:33
@ViktorLatypov I haven't thought about what to aim at. I declared my own out vec4 but still fails to compile. Could you show an example of both Core profile and compatibility profile for my shader ? This way I can see if this is the case or something else is going on. –  Yonathan Jul 24 '12 at 15:35
Added an update, its not due to the shaders itself. –  Yonathan Jul 25 '12 at 8:21

Your Answer



Browse other questions tagged or ask your own question.