xcode – 在Swift中初始化NSOpenGLPixelFormat

前端之家收集整理的这篇文章主要介绍了xcode – 在Swift中初始化NSOpenGLPixelFormat前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_403_3@
显然我是唯一一个尝试这一点的人,因为我的谷歌搜索没有任何有用的信息.假设我正在初始化一个属性数组,如下所示:

let glPFAttributes = [
    NSOpenGLPFAAccelerated,NSOpenGLPFADoubleBuffer,NSOpenGLPFAColorSize,48,NSOpenGLPFAAlphaSize,16,NSOpenGLPFAMultisample,NSOpenGLPFASampleBuffers,1,NSOpenGLPFASamples,4,NSOpenGLPFAMinimumPolicy,0
]

这些都是常规的Ints,我已经检查过了.现在,如果我这样做

let glPixelFormat = NSOpenGLPixelFormat(attributes: glPFAttributes)

编译器给我这个错误信息:

‘Int’ is not identical to ‘NSOpenGLPixelFormatAttribute’

如果我在某个地方犯了错误,我就没有看到它.

解决方法

NSOpenGLPixelFormatAttribute是UInt32的typeAlias. NSOpenGLPixelFormat intializer接受NSOpenGLPixelFormatAttribute数组,因此您需要创建数组并将所有Int转换为UInt32.Below代码将起作用

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)
@H_403_3@

猜你在找的Xcode相关文章