swift - 我找不到我的 GLSL 代码哪里出错了?
问题描述
我是一名 iOS 开发人员,使用Xcode编译一些GLSL代码。shaderv.vsh
代码如下:
attribute vec4 position;
attribute vec4 positionColor;
attribute vec2 textCoordinate;
uniform mat4 projectionMatrix;
uniform mat4 modelViewMatrix;
varying lowp vec2 varyTextCoord;
varying lowp vec4 varyColor;
void main() {
varyTextCoord = textCoordinate;
varyColor = positionColor;
vec4 vPos;
vPos = projectionMatrix * modelViewMatrix * position;
gl_Position = vPos;
}
shaderf.fsh
代码如下:
precision lowp float;
varying lowp vec2 varyTextCoord;
varying lowp vec4 varyColor;
uniform sampler2D colorMap;
void main() {
vec4 cs = texture2D(colorMap,varyTextCoord);
vec4 cd = varyColor;
float s = 0.2;
float d = 0.5;
vec4 color = (cs * s) + (cd * d);
gl_FragColor = color;
}
编译这段代码时,会出现一些错误:
ERROR: 0:15: 'premature EOF' : syntax error syntax error
ERROR: 0:5: 'premature EOF' : syntax error syntax error
我找不到哪里错了。它困扰了我很长时间。帮我!
解决方案
我已经解决了这个问题。我的着色器代码是正确的。我错误地使用了一个快速功能。
let content = try? String(contentsOfFile: file, encoding: String.Encoding.utf8)
var source = UnsafePointer<GLchar>(content)
shader = glCreateShader(type)
glShaderSource(shader, 1,&source, nil)
编译着色器字符串时,我应该将其转换为 cString。
let content = try? String(contentsOfFile: file, encoding: String.Encoding.utf8)
let contentCString = content?.cString(using: .utf8)
var source = UnsafePointer<GLchar>(contentCString)
感谢大家提示我。
推荐阅读
- python-3.x - python 3 multiprocessing freeze_support() 是否将启动方法设置为生成?
- python-3.x - 在 TensorFlow2 中使用学习率计划和学习率预热
- python - 如何将 pandas 中的数据框求和超过 5
- java - 如果不是付费内容,如何点击网页元素?- Selenium Webdriver (Java)
- bash - 触摸,打开,在 Mac 10.15.6 终端上不起作用,PATH 问题
- mongodb - 分面搜索和选择多个值 - mongodb $facet
- php - BadMethodCallException 调用未定义的方法 App\restaurent_name::session()
- java - 在请求正文中保存实体引用子实体的列
- android - 在 Android 8+ 上停止应用程序时,周期性任务被终止
- julia - 如何创建具有列表理解的二维数组?