xcode Open GL 错误:使用未声明的标识符“gl_FragColor”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11328792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open GL Error: Use of undeclared identifier 'gl_FragColor'
提问by Sumanth
I am not understanding what was the error here. Please tell me how to resolve the error i am new to openGL developement. It is not compiling it is showing error like this ERROR: 0:4: Use of undeclared identifier 'gl_FragColor'
我不明白这里的错误是什么。请告诉我如何解决我是 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);
}
回答by Sumanth
Modify the line 2
like this
2
像这样修改行
GLuint fragmentShader = [self compileShader:@"SimpleFragment" withType:GL_FRAGMENT_SHADER];
You should compile fragments in Fragment shader.
您应该在片段着色器中编译片段。