Open GL Error:使用未声明的标识符'gl_FragColor'

时间:2012-07-04 12:07:16

标签: iphone ios xcode

我不明白这里的错误是什么。请告诉我如何解决我对openGL开发的新错误。它没有编译它显示错误,如ERROR: 0:4: Use of undeclared identifier 'gl_FragColor'

-(void)compileShaders{
GLuint vertexShader = [self compileShader:@"SimpleVertex" withType:GL_VERTEX_SHADER];
GLuint fragmentShader = [self compileShader:@"SimpleFragment" withType:GL_VERTEX_SHADER];

GLuint programHandle = glCreateProgram();
glAttachShader(programHandle, vertexShader);
glAttachShader(programHandle, fragmentShader);
glLinkProgram(programHandle);

GLint linkSuccess;
glGetProgramiv(programHandle, GL_LINK_STATUS, &linkSuccess);
if (linkSuccess == GL_FALSE) {
    GLchar messages[256];
    glGetProgramInfoLog(programHandle, sizeof(messages), 0, &messages[0]);
    NSString *messageString = [NSString stringWithUTF8String:messages];
    NSLog(@"%@",messageString);
    exit(1);
}
glUseProgram(programHandle);
_positionSlot = glGetAttribLocation(programHandle, "Position");
_colorSlot = glGetAttribLocation(programHandle, "Sourcecolor");
glEnableVertexAttribArray(_positionSlot);
glEnableVertexAttribArray(_colorSlot);
}

1 个答案:

答案 0 :(得分:9)

像这样修改行2

GLuint fragmentShader = [self compileShader:@"SimpleFragment" withType:GL_FRAGMENT_SHADER];

您应该在Fragment着色器中编译片段。