How to do it...

After linking and enabling the shader program, use the following code to display the list of active attributes:

  1. Start by querying for the number of active attributes:
GLint numAttribs; 
glGetProgramInterfaceiv(programHandle, GL_PROGRAM_INPUT,        GL_ACTIVE_RESOURCES, &numAttribs);
  1. Loop through each attribute, query for the length of the name, the type, and the attribute location, and print the results to standard out:
GLenum properties[] = {GL_NAME_LENGTH, GL_TYPE, GL_LOCATION};
 
std::cout << "Active attributes" << std::endl; 
for( int i = 0; i < numAttribs; ++i ) { 
  GLint results[3]; 
  glGetProgramResourceiv(programHhandle, GL_PROGRAM_INPUT, i, 3, properties, 3, NULL, results); GLint nameBufSize = results[0] + 1; char * name = ...

Get OpenGL 4 Shading Language Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.