我在 HTC Desire S 上创建了一个使用 GLES2.0 的应用程序。它适用于 HTC,但不适用于三星 Galaxy tab10.1。该程序无法链接(GLES20.glGetProgramiv(mProgram, GLES20.GL_LINK_STATUS, linOk,0) 给出-1)并且 glGetError() 给我一个错误 1282(无效操作)。
当我替换这条线(在着色器中)时:
graph_coord.z = (texture2D(mytexture, graph_coord.xy / 2.0 + 0.5).r);
经过
graph_coord.z = 0.2;
它也适用于银河选项卡。我的着色器看起来像这样:
private final String vertexShaderCode =
"attribute vec2 coord2d;" +
"varying vec4 graph_coord;" +
"uniform mat4 texture_transform;" +
"uniform mat4 vertex_transform;" +
"uniform sampler2D mytexture;" +
"void main(void) {" +
" graph_coord = texture_transform * vec4(coord2d, 0, 1);" +
" graph_coord.z = (texture2D(mytexture, graph_coord.xy / 2.0 + 0.5).r);" +
" gl_Position = vertex_transform * vec4(coord2d, graph_coord.z, 1);" +
"}";
那是附加着色器的地方:
mProgram = GLES20.glCreateProgram(); // create empty OpenGL Program
GLES20.glAttachShader(mProgram, vertexShader); // add the vertex shader to program
GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program
GLES20.glLinkProgram(mProgram); // create OpenGL program executables
int linOk[] = new int[1];
GLES20.glGetProgramiv(mProgram, GLES20.GL_LINK_STATUS, linOk,0);
纹理在这里加载:
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture_id[0]);
GLES20.glTexImage2D(
GLES20.GL_TEXTURE_2D, // target
0, // level, 0 = base, no minimap,
GLES20.GL_LUMINANCE, // internalformat
size, // width
size, // height
0, // border, always 0 in OpenGL ES
GLES20.GL_LUMINANCE, // format
GLES20.GL_UNSIGNED_BYTE, // type
values
);