如何在 Xcode OS X Swift Playground 中使用 GLKit?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24009090/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use GLKit within the Xcode OS X Swift Playground?
提问by darrinm
I'm trying to use GLKit within the Xcode 6 OS X Swift Playground but the
我正在尝试在 Xcode 6 OS X Swift Playground 中使用 GLKit,但是
import GLKit
doesn't seem enough to make Playground recognize GLKView. Any ideas?
似乎不足以让 Playground 识别 GLKView。有任何想法吗?
import Cocoa
import GLKit
import OpenGL
let frame = CGRect(x: 0, y: 0, width: 400, height: 300)
class TriangleView: GLKView { // ERROR: Use of undeclared type 'GLKView'
override func drawRect(dirtyRect: NSRect) {
glClearColor(0.0, 0.0, 0.1, 1.0)
}
}
回答by Waruna
You can create iOS project and add new .playground file inside that project. Then you can import GLkit, I also had to import OpenGLES instead of OpenGL.
您可以创建 iOS 项目并在该项目中添加新的 .playground 文件。然后你可以导入GLkit,我也不得不导入OpenGLES而不是OpenGL。
import UIKit
import GLKit
import OpenGLES
let frame = CGRect(x: 0, y: 0, width: 400, height: 300)
class TriangleView: GLKView { // ERROR: Use of undeclared type 'GLKView'
override func drawRect(dirtyRect: CGRect) {
glClearColor(0.0, 0.0, 0.1, 1.0)
}
}
回答by darrinm
There is no GLKView in OS X! From Apple documentation:
OS X 中没有 GLKView!来自苹果文档:
In OS X, NSOpenGLView class subsumes the GLKView and GLKViewController classes in iOS.
在 OS X 中,NSOpenGLView 类包含了 iOS 中的 GLKView 和 GLKViewController 类。