显然我是唯一一个尝试这样做的人,因为我的 Google 搜索都没有找到任何有用的东西。假设我正在像这样初始化一个属性数组:
let glPFAttributes = [
NSOpenGLPFAAccelerated,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAColorSize, 48,
NSOpenGLPFAAlphaSize, 16,
NSOpenGLPFAMultisample,
NSOpenGLPFASampleBuffers, 1,
NSOpenGLPFASamples, 4,
NSOpenGLPFAMinimumPolicy,
0
]
这些东西都是常规的 Int,我已经检查过了。现在如果我这样做
let glPixelFormat = NSOpenGLPixelFormat(attributes: glPFAttributes)
编译器给我这个错误信息:
'Int' is not identical to 'NSOpenGLPixelFormatAttribute'
如果我在某处犯了错误,我不会看到它。
最佳答案
NSOpenGLPixelFormatAttribute
是 UInt32
的 typeAlias
。 NSOpenGLPixelFormat
初始化器采用 NSOpenGLPixelFormatAttribute
数组,因此您需要制作数组并将所有 Int
转换为 UInt32
。下面的代码将工作
let glPFAttributes:[NSOpenGLPixelFormatAttribute] = [
UInt32(NSOpenGLPFAAccelerated),
UInt32(NSOpenGLPFADoubleBuffer),
UInt32(NSOpenGLPFAColorSize), UInt32(48),
UInt32(NSOpenGLPFAAlphaSize), UInt32(16),
UInt32(NSOpenGLPFAMultisample),
UInt32(NSOpenGLPFASampleBuffers), UInt32(1),
UInt32(NSOpenGLPFASamples), UInt32(4),
UInt32(NSOpenGLPFAMinimumPolicy),
UInt32(0)
]
let glPixelFormat = NSOpenGLPixelFormat(attributes: glPFAttributes)
关于xcode - 在 Swift 中初始化 NSOpenGLPixelFormat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26563376/