美文网首页
Swift使用String 转 GLchar 时是遇到问题

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

作者: Mr_滑 | 来源:发表于2019-06-04 16:15 被阅读0次

    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)

    相关文章

      网友评论

          本文标题:Swift使用String 转 GLchar 时是遇到问题

          本文链接:https://www.haomeiwen.com/subject/iwqrxctx.html