当我将NSOpenGLProfileVersion3_2Core添加到属性时,pixelformat变量为nil,但是当我删除它时,像素格式被分配。我不明白是什么问题:(
GLuint attributes[] = {
NSOpenGLProfileVersionLegacy,
NSOpenGLProfileVersion3_2Core,
NSOpenGLPFAWindow,
NSOpenGLPFAColorSize, 24,
NSOpenGLPFAAlphaSize, 8,
NSOpenGLPFAAccelerated,
NSOpenGLPFADoubleBuffer,
0
};
_pixelformat = [[NSOpenGLPixelFormat alloc]
initWithAttributes:
(NSOpenGLPixelFormatAttribute *) attributes];
if (_pixelformat == nil){
NSLog(@"No valid OpenGL pixel format");
exit(0);
}
NSLog(@"Have a valid pixel format");
结果是“没有有效的OpenGL像素格式。”
答案 0 :(得分:2)
genpfault有正确的想法,但这些属性都不是唯一有效的。也就是说,它们不是布尔属性/标志。
您需要将常量与适当的属性名称匹配。
GLuint attributes[] = {
NSOpenGLProfileVersionLegacy,
NSOpenGLProfileVersion3_2Core,
[...]
NSOpenGLPixelFormatAttribute attributes[] = {
NSOpenGLPFAOpenGLProfile, (NSOpenGLPixelFormatAttribute)NSOpenGLProfileVersion3_2Core,
[...]
我也冒昧地纠正了你对typedef的使用。 NSOpenGLPixelFormatAttribute
定义为uint32_t
,而OpenGL要求GLuint
为无符号整数类型 至少 32位宽。 OpenGL不会禁止GLuint
在未来使用uint64_t
这样的内容进行实施。
答案 1 :(得分:1)
解决。需要删除NSOpenGLPFAWindow属性。
答案 2 :(得分:0)
NSOpenGLProfileVersionLegacy,
NSOpenGLProfileVersion3_2Core,
选择一个。你不能同时拥有Core和非Core的上下文。