如何在Xcode OS X Swift Playground中使用GLKit?

时间:2022-03-18 11:14:51

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)
    }
}

2 个解决方案

#1


8  

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)
    }
}

#2


3  

There is no GLKView in OS X! From Apple documentation:

OS X中没有GLKView!来自Apple文档:

In OS X, NSOpenGLView class subsumes the GLKView and GLKViewController classes in iOS.

在OS X中,NSOpenGLView类包含iOS中的GLKView和GLKViewController类。

#1


8  

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)
    }
}

#2


3  

There is no GLKView in OS X! From Apple documentation:

OS X中没有GLKView!来自Apple文档:

In OS X, NSOpenGLView class subsumes the GLKView and GLKViewController classes in iOS.

在OS X中,NSOpenGLView类包含iOS中的GLKView和GLKViewController类。