OpenGL コンテキストを NSWindow に追加しようとしていますが、何らかの理由で機能しません。アプリを実行すると NSWindow が正しく作成および表示されますが、OpenGL コンテキストでは何もできないため、コンテキストが NSWindow に正しく追加されていないと推測されます。
これまでの私のコードは次のとおりです。
import Foundation
import AppKit
import GLKit
let application = NSApplication.sharedApplication()
application.setActivationPolicy(NSApplicationActivationPolicy.Regular)
let window = NSWindow(contentRect: NSMakeRect(0, 0, 640, 480), styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask, backing: .Buffered, defer: false)
window.center()
window.title = "Programmatically Created Window"
window.makeKeyAndOrderFront(window)
class WindowDelegate: NSObject, NSWindowDelegate {
func windowWillClose(notification: NSNotification) {
NSApplication.sharedApplication().terminate(0)
}
}
let windowDelegate = WindowDelegate()
window.delegate = windowDelegate
class AppDelegate: NSObject, NSApplicationDelegate {
var window: NSWindow
init(window: NSWindow) {
self.window = window
}
func applicationDidFinishLaunching(notification: NSNotification) {
let glContext = NSOpenGLView()
self.window.contentView.addSubview(glContext)
// let glAttributes: [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 pixelFormat = NSOpenGLPixelFormat(attributes: glAttributes)
// let glContext = NSOpenGLContext(format: pixelFormat, shareContext: nil)
// self.window.contentView.addSubview(glContext!.view)
// glContext!.view = self.window.contentView as NSView
}
}
let applicationDelegate = AppDelegate(window: window)
application.delegate = applicationDelegate
application.activateIgnoringOtherApps(true)
application.run()
glClearColor(0, 0, 0, 0)