I am trying to add the translation to a simple example of drawing a triangle using OpenGL ES 2.0 for Android. I have created translation matrix with 0 translation in all directions which should be the identity matrix. When I remove the multiplication from vertex shader triangle renders fine. However when I try to add some transformation(even identity) nothing is rendered. I think it is something about sending matrix data to the shader. GL.UniformMatrix 4 only takes float as attributes and I cant convert Matrix4 to float array. At the end I desperately created float array for identity matrix and passed it using GL.UniformMAtrix4 however nothing is rendered again.
Can anyone with the experience help me out please.
Matrix4 uvMat = Matrix4.CreateTranslation(0.0f,0.0f,0.0f);
// Vertex and fragment shaders
string vertexShaderSrc = "attribute vec4 vPosition; \n" +
"uniform mat4 uvMat; \n" +
"void main() \n" +
"{ \n" +
" gl_Position = uvMat*vPosition; \n" +
"} \n";
string fragmentShaderSrc = "precision mediump float;\n" +
"void main() \n" +
"{ \n" +
" gl_FragColor = vec4 (1.0, 0.0, 0.0, 1.0); \n" +
"} \n";
int vertexShader = LoadShader (All.VertexShader, vertexShaderSrc );
int fragmentShader = LoadShader (All.FragmentShader, fragmentShaderSrc );
program = GL.CreateProgram();
if (program == 0)
throw new InvalidOperationException ("Unable to create program");
GL.AttachShader (program, vertexShader);
GL.AttachShader (program, fragmentShader);
GL.BindAttribLocation (program, 0, "vPosition");
GL.LinkProgram (program);
float[] matTrans = new float[] {1,0,0,0,
0,1,0,0,
0,0,1,0,
0,0,0,1};
int uniMatLoc = GL.GetUniformLocation (program, "uvMat");
Console.WriteLine (uniMatLoc.ToString());
GL.UniformMatrix4 (uniMatLoc, 16, false, matTrans);