OpenGL ES着色器编译



我正在尝试使用opengl创建应用程序。在实际设备上调试。我创建这样的上下文::

GLSurfaceView baseView = new GLSurfaceView(this);
baseView.setEGLContextClientVersion(3);
baseView.setRenderer(new GameView());

我编译着色器如下:

int program = GLES20.glCreateProgram();
int idShad = (type == 0) ? GLES20.GL_VERTEX_SHADER : GLES20.GL_FRAGMENT_SHADER;
int shader = GLES20.glCreateShader(idShad);
GLES20.glShaderSource(shader, source);
GLES20.glCompileShader(shader);
int[] isCompiled = new int[1];
glGetShaderiv(shader, GL_COMPILE_STATUS, isCompiled, 0);
if (isCompiled[0] == GL_FALSE) {
String infoLog = "";
infoLog = glGetShaderInfoLog(shader);
glDeleteShader(shader);
String typeShader = (type == 0) ? "Vertex Shader" : "Fragment Shader";
Log.e("OpenGl", "Cannot compile " + typeShader + ": " + infoLog);
System.exit(-1);
}
glAttachShader(program, shader);

但我总是收到这样的错误:

无法编译:顶点着色器:0:3:L0001:需要Typename,找到'�'

从文件加载和在代码中创建一行时,我会得到它对于任何代码,甚至是空着色器,以下是示例:

public static final String baseMatrixVX = 
"#version 300 esn"
+ "void main() {n"
+ "}";
public static final String texMatrixVX =
"#version 330n"
+ "layout(location = 0) in vec3 pos;n"
+ "layout(location = 1) in vec3 color;n"
+ "layout(location = 2) in vec2 tex;n"
+ "out vec3 colorOut;n"
+ "out vec2 texOut;n"
+ "uniform bool enabledCam;n"
+ "uniform mat4 projection;n"
+ "uniform mat4 cam;n"
+ "uniform mat4 model;n"
+ "void main() {n"
+ "if (enabledCam) {n"
+ "    gl_Position = projection * model * cam * vec4(pos, 1.0f);n"
+ "} else {n"
+ "    gl_Position = projection * model * vec4(pos, 1.0f);n"
+ "}n"
+ "colorOut = vec3(color);n"
+ "texOut = tex;n"
+ "}";

我做错了什么?

p.S设备支持opengle es 3及以上

原来问题出在最后一个字符\0。应该使用

最新更新