NSOpenGL配置文件版本3_2Core

时间:2013-11-12 16:22:49

标签: xcode macos opengl

当我将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像素格式。”

3 个答案:

答案 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这样的内容进行实施。

尽可能使用正确的API定义的typedef。

答案 1 :(得分:1)

解决。需要删除NSOpenGLPFAWindow属性。

答案 2 :(得分:0)

    NSOpenGLProfileVersionLegacy,
    NSOpenGLProfileVersion3_2Core,

选择一个。你不能同时拥有Core和非Core的上下文。