目前正试图让我的C ++源代码在iOS上运行。它在OpenGLES 2.0中运行在Android上,我已经完成了编译的所有内容,但是我在编译着色器时遇到了问题。出于某种原因,glCreateShader(GL_VERTEX_SHADER)
返回0.这是我的视图控制器代码:
import Foundation
import GLKit
import OpenGLES
class SampleViewController: GLKViewController {
@IBOutlet var glview: GLKView!
override func viewDidLoad() {
super.viewDidLoad()
glview.context = EAGLContext(API: .OpenGLES2)
glview.drawableColorFormat = .RGBA8888
glview.drawableDepthFormat = .Format16
glview.drawableMultisample = .MultisampleNone
glview.drawableStencilFormat = .FormatNone
preferredFramesPerSecond = 60
let s = NSBundle.mainBundle().URLForResource("Arial", withExtension: ".ttf")?.relativePath
let cs = (s! as NSString).UTF8String
let buffer = UnsafeMutablePointer<Int8>(cs)
appInit(buffer)
}
override func glkView(view: GLKView, drawInRect rect: CGRect) {
super.glkView(view, drawInRect: rect)
glview.bindDrawable()
appRender(Int(timeSinceLastDraw * 1000), Int32(rect.width), Int32(rect.height))
}
}
这与故事板上的GLKViewController
相关联。
注意:appInit(buffer)
是对通过桥接头导入的C ++代码的调用。
答案 0 :(得分:0)
显然我必须在appInit
覆盖内部运行drawInRect
函数,因为这是glContext
存在的第一个地方。
固定代码:
import Foundation
import GLKit
import OpenGLES
class GanttViewController: GLKViewController {
@IBOutlet var glview: GLKView!
private var program = 0
override func viewDidLoad() {
super.viewDidLoad()
glview.context = EAGLContext(API: .OpenGLES2)
glview.drawableColorFormat = .RGBA8888
glview.drawableDepthFormat = .Format16
glview.drawableMultisample = .MultisampleNone
glview.drawableStencilFormat = .FormatNone
preferredFramesPerSecond = 60
program = 0
}
override func glkView(view: GLKView, drawInRect rect: CGRect) {
super.glkView(view, drawInRect: rect)
if(program == 0){
let s = NSBundle.mainBundle().URLForResource("Arial", withExtension: ".ttf")?.relativePath
let cs = (s! as NSString).UTF8String
let buffer = UnsafeMutablePointer<Int8>(cs)
appInit(buffer)
program = 1
}
glview.bindDrawable()
appRender(Int(timeSinceLastDraw * 1000), Int32(rect.width), Int32(rect.height))
}
}