Debugging shader with no errors

I have setup the usual code for setting up a GLSL program, but after error checking and not getting errors, glUseProgram doesn’t change the program. I’m wondering if the glGetShaderInfoLog and glGetProgramInfoLog don’t turn up any errors after being setup, what else can you debug to see why glUseProgram doesn’t start the program?

Here’s my setup code:

  const GLsizei maxLength = 1000;
  GLsizei log_length;
  GLchar log[maxLength];

  // allocate the shaders
  GLuint v = glCreateShader(GL_VERTEX_SHADER);
  GLuint f = glCreateShader(GL_FRAGMENT_SHADER);
  GLint length[1];
  const GLchar* source[1];

  // create vertex shader
  source[0] = v_source;
  length[0] = strlen(source[0]);
  glShaderSource(v, 1, source, length);

  // check vertex compilation
  glGetShaderInfoLog(v, maxLength, &log_length, log);
  std::cout << log;

  // create fragment shader
  source[0] = f_source;
  length[0] = strlen(source[0]);
  glShaderSource(f, 1, source, length);

  // check fragment compilation
  glGetShaderInfoLog(f, maxLength, &log_length, log);
  std::cout << log;

  program = glCreateProgram();
  glAttachShader(program, v);
  glAttachShader(program, f);

  glGetProgramInfoLog(program, maxLength, &log_length, log);
  std::cout << log;


  glGetProgramInfoLog(program, maxLength, &log_length, log);
  std::cout << log;

  cout << "Created program" << endl; 

At the very least you should probably check the link status after linking your program (GetProgramiv with LINK_STATUS), and for good measure a compile status check wouldn’t hurt (GetShaderiv with COMPILE_STATUS).

P.S. Wouldn’t hardcode that array length if I were you! :wink: (Look at GetShaderiv/GetProgramiv with INFO_LOG_LENGTH.)

The spec.

The spec on info logs

If shader is a shader object, the returned info log will either be an empty string
or it will contain information about the last compilation attempt for that object. If
program is a program object, the returned info log will either be an empty string or
it will contain information about the last link attempt or last validation attempt for
that object.
The info log is typically only useful during application development and an
application should not expect different GL implementations to produce identical
info logs.

Each program object has an information log that is overwritten as a result of a
link operation. This information log can be queried with GetProgramInfoLog to
obtain more information about the link operation or the validation information.

So error information isn’t strictly required to be written to the logs (though in practice it usually is).

Yes, but some errors can just cause the surfaces not to be rendered, or rendered improperly without even a hint in the info log.

Try glslDevil.

glslDevil is quite nice. i use RenderMonkey once in a while because it supports GLSL, compiling and checking shaders right away and has a somewhat pretty interface. Pretty good tool for developing and testing shaders.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.