View Full Version : Android SDK // Eclipse // OPENGL ES 2.0 -> Shader Question

08-15-2011, 03:19 PM

i try to use openGL ES 2.0 Shader ..but i am not able to load the vertex/fragment source

opengl 2.0 is supported at my mobile phone ( info.getGlEsVersion() -> 2.0)

i am using the android sdk (sdk manager) under Win7 with eclipse.

testing at samsung galaxy s2 and the emulator

i downloaded the NDK but i am not able to use it, because my english is not soo
good to understand what to do.(downloading and extraction is not a problem)

i open sample projekt (that i did understand in the manual..project from existing scource...) and build the apk..
but when loading to mobile phone..it crashes..
i think i need to link anything with anything i did not know where...
maybe anything like libarys..etc...

i hope and pray i did not need the ndk and opengl2 is working with the android sdk

much greetings

and thanks for all help i may get :)

public int createProgram() {

String vertexSource = "uniform mat4 u_mvpMatrix;"+
"attribute vec4 a_position;"+
"attribute vec4 a_color;"+
"varying vec4 v_color;"+
"void main() {"+
"gl_Position = u_mvpMatrix * a_position;"+
"v_color = a_color;"+

String fragmentSource = "precision mediump float;"+
"varying vec4 v_color;"+
"void main()\n {"+
"gl_FragColor = v_color;";

is_error_text+="loading Shader / ";

int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
if (pixelShader == 0) {
is_error_text+=" FS error ";
return 0;

int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
if (vertexShader == 0) {
is_error_text+=" VS error ";
return 0;

private int loadShader(int shaderType, String source) {
int shader = GLES20.glCreateShader(shaderType);
if (shader != 0) {
GLES20.glShaderSource(shader, source);
int[] compiled = new int[1];
GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
if (compiled[0] == 0) {
Log.e(TAG, "Could not compile shader " + shaderType + ":");
Log.e(TAG, GLES20.glGetShaderInfoLog(shader));
shader = 0;
return shader;

08-16-2011, 05:11 AM
Your fragment shader seems to be lacking a closing }. That shouldn't cause a crash, though.

09-10-2011, 10:03 PM
try in Eclipse:Project->Clean..