glCreateShader fails on osx 10.8.2

ringoringo wrote on Wednesday, March 27, 2013:

On 3.0head, (github 4c0e946da3bbc7c24062984467b419cbd8ed0c30)
glCreateShader returns always 0 (fail) on OSX 10.8.2.
on 2.7.7, it succeeds.

You can reproduce this issue by adding some lines in examples/boing.c main() as follows:

int main( void )                                                                                                    
{                                                                                                                   
   GLFWwindow* window;                                                                                              
   int width, height;                                                                                               
                                                                                                                    
   /* Init GLFW */                                                                                                  
   if( !glfwInit() )                                                                                                
      exit( EXIT_FAILURE );                                                                                         
                                                                                                                    
   glfwWindowHint(GLFW_DEPTH_BITS, 16);                                                                             
                                                                                                                    
   window = glfwCreateWindow( 400, 400, "Boing (classic Amiga demo)", NULL, NULL );                                 
   if (!window)                                                                                                     
   {                                                                                                                
       glfwTerminate();                                                                                             
       exit( EXIT_FAILURE );                                                                                        
   }                                                                                                                
                                                                                                                    
   GLuint n = glCreateShader( GL_FRAGMENT_SHADER );     // this always fails
   assert( n > 0 );  
   // ...

In 2.7.7, this successes:


int main( void )                                                                                                    
{                                                                                                                   
   int running;                                                                                                     
                                                                                                                    
   /* Init GLFW */                                                                                                  
   if( !glfwInit() )                                                                                                
   {                                                                                                                
      fprintf( stderr, "Failed to initialize GLFW\n" );                                                             
      exit( EXIT_FAILURE );                                                                                         
   }                                                                                                                
                                                                                                                    
   if( !glfwOpenWindow( 400,400, 0,0,0,0, 16,0, GLFW_WINDOW ) )                                                     
   {                                                                                                                
       fprintf( stderr, "Failed to open GLFW window\n" );                                                           
       glfwTerminate();                                                                                             
       exit( EXIT_FAILURE );                                                                                        
   }                                                                                                                
                                                                                                                    
   GLuint n = glCreateShader( GL_FRAGMENT_SHADER ); // succeed here                                                                 
   assert( n > 0 );   

How to fix this?

palmer789 wrote on Wednesday, January 20, 2016:

I have met the same problem with you… Have you solved this issue.Be different with you, I am on PC.

bastiaanolij wrote on Thursday, January 21, 2016:

Kengo, are you sure returning 0 is a problem? Many OpenGL objects start counting at 0 so a shader with ID 0 may not be an issue.

This is my shader init code:

	// create our shader
	shader = glCreateShader(pShaderType);
  
	// compile our shader
	stringptrs[0] = pShaderText;
	glShaderSource(shader, 1, stringptrs, NULL);
	glCompileShader(shader);
  
	// check our status
	glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
	if (!compiled) { 
         ...

Note how I do not check anything until after I attempt to compile my shader. I’m testing this on 10.11 but I started my project when I was still on 10.8 so…

You can find the full source here: https://github.com/BastiaanOlij/glfw-tutorial/blob/master/include/shaders.h

bastiaanolij wrote on Thursday, January 21, 2016:

Hmm, indeed manual pages here:
https://www.opengl.org/sdk/docs/man/html/glCreateShader.xhtml

Say 0 is failure… I better add that:)

bastiaanolij wrote on Thursday, January 21, 2016:

Hmmm one extra thing I do that is in the samples is that you need to call glfwMakeContextCurrent after constructing your window so:

window = glfwCreateWindow(...
if (window == NULL) {
  // error
};

// make context current
glfwMakeContextCurrent(window)

// now init your shader