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 3 of 3

Thread: check if shaders compiled

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    4

    check if shaders compiled

    I just recently got "The OpenGL Superbible" as my first opengl book and am starting to learn opengl 3.x+. Anyway, between that and the examples at mechcore.net i have written my first program, but I can't get any shader errors. Here is my shader loading code:
    Code :
        void setupShaders()
        {
            GLint testval;
            GLint abort = 0;
     
            //Set Filenames
            string vertexFName = "vertex.shader";
            string fragFName = "fragment.shader";
     
            //create variables needed
            string source;
            const char* source_c; //cstr version for OGL
            const char* sour;
     
            //create shaders and the program
            vertexShader = glCreateShader(GL_VERTEX_SHADER);
            fragShader = glCreateShader(GL_FRAGMENT_SHADER);
            shaderProg = glCreateProgram();
     
            //load vertex shader
            source = loadFromFile(vertexFName);
            source_c = source.c_str();
            sour = source_c;
            glShaderSource(vertexShader, 1, &source_c, NULL);
     
            //load fragment shader
            source = loadFromFile(fragFName);
            source_c = source.c_str();
            glShaderSource(fragShader, 1, &source_c, NULL);
     
            //compile and link
            glCompileShader(vertexShader);
            glCompileShader(fragShader);
     
            glAttachShader(shaderProg, vertexShader);
            glAttachShader(shaderProg, fragShader);
            glLinkProgram(shaderProg);
     
            //catch any errors
            glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &testval);
            if(testval == GL_FALSE)
            {
                abort = 1;
                char infolog[1024];
                glGetShaderInfoLog(vertexShader,1024,NULL,infolog);
                cout << "The vertex shader failed to compile with the error:" << endl << infolog << endl;
            }
     
            glGetShaderiv(fragShader, GL_COMPILE_STATUS, &amp;testval);
            if(testval == GL_FALSE)
            {
                abort = 1;
                char infolog[1024];
                glGetShaderInfoLog(fragShader,1024,NULL,infolog);
                cout << "The fragment shader failed to compile with the error:" << endl << infolog << endl;
            }
     
            glGetProgramiv(shaderProg, GL_LINK_STATUS, &amp;testval);
            if(testval == GL_FALSE)
            {
                abort = 1;
                char infolog[1024];
                glGetProgramInfoLog(shaderProg,1024,NULL,infolog);
                cout << "The program failed to compile with the error:" << endl << infolog << endl;
            }
            if(abort)
            {
                cout << "errors occured, cannot continue, aborting." << endl;
                exit(-1);
            }
    Sorry about the length,

    EDIT: oh, the output may help, it outputs
    The vertex shader failed to compile with the error:
    
    The fragment shader failed to compile with the error:
    
    The program failed to compile with the error:
    
    errors occured, cannot continue, aborting.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Singapore
    Posts
    802

    Re: check if shaders compiled

    Hi,
    Could we see what your shader contains?

    Thanks,
    Mobeen
    Regards,
    Mobeen

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    4

    Re: check if shaders compiled

    Gah, why is notify not working? Anyway, i found the problem on my own, I forgot to initialize opengl... =P

Posting Permissions

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