opengl – 如何在glShaderSource中将String作为GLchar **(char **)参数传递?

前端之家收集整理的这篇文章主要介绍了opengl – 如何在glShaderSource中将String作为GLchar **(char **)参数传递?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个存储在String值中的着色器:
var myShader = 
    "    attribute vec4 a_position;" +
    "    void main() {" +
    "    gl_Position = a_position;" +
    "    }"

    glShaderSource(shader,GLsizei(1),myShader,nil)

函数glShaderSource具有绑定签名:

func glShaderSource(shader: GLuint,count: GLsizei,string: UnsafePointer<UnsafePointer<GLchar>>,length: UnsafePointer<GLint>)

当我尝试直接将着色器String传递给glShaderSource时,我收到错误消息:

'String' is not convertible to 'UnsafePointer<UnsafePointer<GLchar>>'

如何正确传递String? (xCode版本6.1(6A1052d))

经过半天的搜索,我找到了没有编译错误的工作解决方案,错误的内存访问失败了:
var cStringSource = (code as NSString).UTF8String
glShaderSource(shader,&cStringSource,nil)
原文链接:https://www.f2er.com/swift/319014.html

猜你在找的Swift相关文章