xcode - 在 Swift 中初始化 NSOpenGLPixelFormat

标签 xcode macos opengl swift nsopenglview

显然我是唯一一个尝试这样做的人,因为我的 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'

如果我在某处犯了错误,我不会看到它。

最佳答案

NSOpenGLPixelFormatAttributeUInt32typeAliasNSOpenGLPixelFormat 初始化器采用 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/

相关文章:

c++ - Opengl 未定义行为

iphone - 在 View Controller 之间切换时自动旋转

macos - GIT 无法 pull : failed to symlink 'path/filename' : File name too long

macos - NSScreen 获取投影仪/电视输出/AirPlay 屏幕?

c - 使用绘图库制作 GUI

c++ - 如何在 opengl Tessellation Evaluation 着色器中插入矩阵

ios - iAd 横幅在 segue 上变白

ios - 在 ARKit (Xcode) 中的 ARSCNView 上滑动

ios - UIView 动画无法与 NSLayoutConstraint 一起使用?

ruby - 目录内容是否已更改?