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: writing a shader error checker in C

  1. #1
    Intern Contributor
    Join Date
    Jun 2013
    Posts
    69

    writing a shader error checker in C

    hi im writing a simple shader error checker in C to check for errors on compilation and link time. im having a big problem with getting the glShaderSource() function to work. i first create space for the code using malloc(codelength * sizeof(char)) then i attach the source to a created shader object with this line glShaderSource(shader, 1, (const char **) &code, NULL);. i belive the problem is with this line. ive even tried changing NULL to the length of the code but to no avail. when i try to get info on the shader it returns zero to glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &compileloglength); and zero to glGetShaderiv(shaders[0], GL_COMPILE_STATUS, &compileloglength); please donbe t point me to a shader error checker that is already out there, unless it has relevant code because i like doing little projects like these. any help would be great. thanks

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    Code :
    bool  CompileShaderFromMemory(GLuint p_ID, const char* p_ShaderString)
    {
        glShaderSource( p_ID, 1, (const char **)&p_ShaderString, 0 );
        // Compile the shader, and check if there were compilation errors
         glCompileShader( p_ID );
     
        GLint compiled = 0;
        glGetShaderiv( p_ID, GL_COMPILE_STATUS, &compiled);
        // If there were compile errors, we might want to print them out.
        if (!compiled)
        {
          GLint l,l1;
          glGetShaderiv(p_ID,GL_INFO_LOG_LENGTH,&l);
            GLchar* compilerSpew = new GLchar[l+1];
            glGetShaderInfoLog(p_ID, l+1, &l1, compilerSpew);
            Util_ErrorLog(compilerSpew);
            Util_Warning(_T("Shader compile failed"));
          delete [] compilerSpew;
            return false;
        }
     
     
        glAttachShader( c_ProgramID, p_ID );
      return true;
    }

  3. #3
    Intern Contributor
    Join Date
    Jun 2013
    Posts
    69
    k i figured it out. i didnt realize i had to make an opengl context for the functions to work

Posting Permissions

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