Swift使用String 转 GLchar 时是遇到问题

2019-06-04  本文已影响0人  Mr_滑

Swift使用String 转  GLchar 时是遇到问题 

var source:  UnsafePointer<GLchar> = (content as? NSString)?.utf8String

let  shader =glCreateShader(type)

glShaderSource(shader,1, &source,nil)

错误提示

Cannot convert value of type 'UnsafePointer<GLchar>' (aka 'UnsafePointer<Int8>') to expected argument type 'UnsafePointer<UnsafePointer<GLchar>?>?' (aka 'Optional<UnsafePointer<Optional<UnsafePointer<Int8>>>>')

后搜索得到方案

let shaderStringUTF8 = content!.cString(using: String.defaultCStringEncoding.rawValue)

var glsource =  UnsafePointer(shaderStringUTF8)

 glShaderSource(shader,1, &source,nil)

上一篇下一篇

猜你喜欢

热点阅读