OpenGL ES 着色器编译

OpenGL ES shader compilation

我正在尝试使用 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);

但我总是收到这个错误:

Cannot compile: Vertex Shader: 0:3: L0001: Typename expected, found '�'

我在从文件加载和在代码中创建一行时得到它 对于任何代码,即使是空着色器,这里都有示例:

    public static final String baseMatrixVX = 
        "#version 300 es\n"
        + "void main() {\n"
        + "}[=12=]";

        public static final String texMatrixVX =
        "#version 330\n"
        + "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"
        + "}[=12=]";

我做错了什么?

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

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