Have you considered checking your OpenGL ES GLSL version on both the android 2.2 device and the android 4.0+ device?
You can print it with GLES20.glGetString(GLES20.GL_SHADING_LANGUAGE_VERSION)
.
android : Error on Shading Language with opengl es2.0 on android 2.2
Question
I have a problem with application. is a simple application atm using opengl es2.0 which running on android 2.2 device HTC sense. I can running the application on my 4.0.3 emulator as well as my device which running android 4.0.
When running on android 2.2, i have this error:
> FATAL EXCEPTION: GLThread 9
java.lang.RuntimeException: Error compiling shader:
SimpleShader.loadShader(SimpleShader.java:87)
SimpleShader.<init>(SimpleShader.java:54)
etc
I assumed that the device can run android 2.2 as the document told LINKS TO DOCUMENTATION, but not sure about the shader part though.
Here is my shader code:
String verticesShader =
"uniform mat4 uScreen;\n" +
"attribute vec2 aPosition;\n" +
"attribute vec3 aColor;\n" +
"attribute vec2 aTexPos; \n" +
"varying vec2 vTexPos; \n" +
"varying vec3 vColor;\n" +
"void main() {\n" +
" vTexPos = aTexPos; \n" +
" gl_Position = uScreen * vec4(aPosition.xy, 0.0, 1.0);\n" +
" vColor = aColor;\n" +
"}";
// Our fragment shader. Just return vColor.
// If you look at this source and just said 'WTF?', remember
// that all the attributes are defined in the VERTEX shader and
// all the 'varying' vars are considered OUTPUT of vertex shader
// and INPUT of the fragment shader. Here we just use the color
// we received and add a alpha value of 1.
String fragmentShader =
"uniform float uUseTexture; \n" +
"uniform float uAlpha; \n" +
"uniform sampler2D uTexture;\n" +
"precision mediump float;\n"+
"varying vec2 vTexPos; \n" +
"varying vec3 vColor;\n" +
"void main(void)\n" +
"{\n" +
" if ( uUseTexture != 1.0 ) \n" +
" gl_FragColor = vec4(vColor.xyz, 1); \n" +
" else \n" +
" gl_FragColor = texture2D(uTexture, vTexPos); \n" +
" gl_FragColor.a *= uAlpha;" +
//" gl_FragColor = vec4(vColor.xyz, 1);\n" +
"}";
private int loadShader(int shader, String shaderSrc) {
// TODO Auto-generated method stub
int handle = GLES20.glCreateShader(shader);
if (handle == GLES20.GL_FALSE)
throw new RuntimeException("Error creating shader!");
GLES20.glShaderSource(handle, shaderSrc);
GLES20.glCompileShader(handle);
int[] compileStatus = new int[1];
GLES20.glGetShaderiv(handle, GLES20.GL_COMPILE_STATUS, compileStatus, 0);
if (compileStatus[0] ==0)
{
String error = GLES20.glGetShaderInfoLog(handle);
GLES20.glDeleteShader(handle);
throw new RuntimeException("Error compiling shader: " + error);
}
else
return handle;
}
The application works fine on my latest device with android 4.0+
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow