gpt4 book ai didi

ios - 为什么 glCreateShader 在 iOS 上返回 0?

转载 作者:行者123 更新时间:2023-11-30 13:15:36 27 4
gpt4 key购买 nike

目前正在尝试让我的 C++ 源代码在 iOS 上运行。它在 Android 上的 OpenGLES 2.0 中运行,我已经完成了编译的所有内容,但在编译着色器时遇到了问题。由于某种原因 glCreateShader(GL_VERTEX_SHADER) 返回 0。这是我的 View Controller 代码:

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

它连接到 Storyboard 上的GLKViewController

注意:appInit(buffer) 是对通过桥接 header 导入的 C++ 代码的调用。

最佳答案

显然我必须在 drawInRect 覆盖内部运行我的 appInit 函数,因为这是 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))
}
}

关于ios - 为什么 glCreateShader 在 iOS 上返回 0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38270605/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com