glCreateShader returns 0

Discussion in 'iOS Programming' started by Blakeasd, Jul 16, 2013.

  1. Blakeasd macrumors 6502a

    Joined:
    Dec 29, 2009
    #1
    Hello,

    For some reason whenever I set either a GLuint or a regular unsigned int equal to glCreateShader, it returns 0?? Take a look at this snippet of code:

    The code is in viewDidLoad:

    Code:
       
        self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
        GLKView *view = (GLKView*)self.view;
        view.context = self.context;
        view.drawableDepthFormat = GLKViewDrawableDepthFormat16;
        
        glEnable(GL_CULL_FACE);
        glEnable(GL_DEPTH_TEST);
        
        int width = self.view.bounds.size.width;
        int height = self.view.bounds.size.height;
        
          
        
        // Read vertex shader source
        NSString *vertexShaderSource = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"VertexShader" ofType:@"vsh"] encoding:NSUTF8StringEncoding error:nil];
        const char *vertexShaderSourceCString = [vertexShaderSource cStringUsingEncoding:NSUTF8StringEncoding];
        
        // Create and compile vertex shader
        GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
        glShaderSource(vertexShader, 1, &vertexShaderSourceCString, NULL);
        glCompileShader(vertexShader);
        
        GLint compiled;
        
        glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &compiled);
        if (!compiled) {
            GLint infoLen = 0;
            glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &infoLen);
            if (infoLen > 1) {
                char *infoLog = malloc(sizeof(char)*infoLen);
                glGetShaderInfoLog(vertexShader, infoLen, NULL, infoLog);
                NSLog(@"Error compiling shader: %s",infoLog);
                free(infoLog);
            }
            exit(1);
        }
        
           if(vertexShader == 0){
            
            NSLog(@"Some sort of vertex error");
        }
        
        NSLog(@"%i",vertexShader);
      
    
    No compiling errors, yet my if statement testing for a NULL shader is called and the value of the shader is 0.

    Could anyone assist me in finding what's happening?

    Thanks!
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    0 indicates there was an error creating the shader. It seems like you probably already knew that, though.
     
  3. Blakeasd thread starter macrumors 6502a

    Joined:
    Dec 29, 2009
    #3
    Perhaps it's a bug in Xcode or the iOS Simulator? I took the exact same project with the exact same code and ran it with the iPhone Simulator rather then the iPad Simulator (which was what I was using before) and it works without any problems.
     

Share This Page