静态glkView(只渲染一次)在UIVC中嵌套:
class SignatureViewController: UIViewController {
override func viewDidLoad() {
//static glkview
class Test: GLKView {
override init(frame: CGRect) {
super.init(frame: frame)
self.context = EAGLContext(api: .openGLES2)!
EAGLContext.setCurrent(self.context)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
//init will trigger once
override func draw(_ rect: CGRect) {
glClearColor(1.0, 0.0, 0.0, 1.0)
glClear(GLbitfield(GL_COLOR_BUFFER_BIT) | GLbitfield(GL_DEPTH_BUFFER_BIT))
print("hello")
}
}
let a = Test(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
self.view.addSubview(a)
}
}
静态glkView在GLKVC中,完全一样,除了UIVC换成GLKVC
class SignatureViewController: GLKViewController {
override func viewDidLoad() {
//static glkview
class Test: GLKView {
override init(frame: CGRect) {
super.init(frame: frame)
self.context = EAGLContext(api: .openGLES2)!
EAGLContext.setCurrent(self.context)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
//init will trigger once
override func draw(_ rect: CGRect) {
glClearColor(1.0, 0.0, 0.0, 1.0)
glClear(GLbitfield(GL_COLOR_BUFFER_BIT) | GLbitfield(GL_DEPTH_BUFFER_BIT))
print("hello")
}
}
let a = Test(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
self.view.addSubview(a)
}
//gameView.context to activate this func
override func glkView(_ view: GLKView, drawIn rect: CGRect) {
}
}