Textures larger and incomplete displayed on Android OpenGL ES 2.0

My aim is to write a game in C++ for Linux, Windows and Android. I use SDL and am able to draw basic geometric shapes using OpenGL ES 2.0 and shaders. But when I try to apply textures to these shapes I recognize, that they appear larger and incomplete on Android. On PC it works fine. My code does not has to be changed to compile for Android. I use Ubuntu 14.10 and test it on it as well as on my Nexus 5 with Android 5.0.1.

I set up an orthographic projection matrix, that gives me a “surface” with an aspect ration of 16:9 in the area x 0.0 to 1.0 and y 0.0 to 0.5625. In this area I draw a rectangle to check that “custom space”:

glClearColor(0.25, 0.0, 0.0, 1.0);

//Configure viewport
glViewport(0, 0, this->width, this->height);

//Update matrices

//Draw rectangle
GLfloat vertices[] = {0.0, 0.0, 0.0, 0.5625, 1.0, 0.0, 1.0, 0.5625};

glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);



The results are following:


Then I draw a square and map a texture to it. Here is the code:


//Enable blending


this->matrix.translate(this->sW/2.0, this->sH/2.0, 0.0);
this->matrix.rotate(rot, 0.0, 0.0, 1.0);
this->matrix.translate(-this->sW/2.0, -this->sH/2.0, 0.0);


float x3 = this->sW/2.0-0.15, x4 = this->sW/2.0+0.15;
float y3 = this->sH/2.0-0.15, y4 = this->sH/2.0+0.15;
GLfloat vertices2[] = {x3, y3, x3, y4, x4, y3, x4, y4};
GLfloat texCoords[] = {0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0};

//Send coordinations to GPU
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices2);

glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, texCoords);

//Bind texture
int u1 = glGetUniformLocation(this->textureShader.getId(), "u_Texture");
glUniform1i(u1, 0);

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);


But this gives me different results:


Then I have tried to modify and test around with the texture coordinates. If I half them, so all 1.0s to 0.5, only the “1 field” of my texture should be displayed? On Linux it is that way, but on Android is just some random area of the texture displayed.

So can anyone give me a hint what I do wrong?

I figured out the problem. I bind my attributes a_Vertex to 0 and a_TexCoordinate to 1. On PC it happens, but on Android it is reversed. So I took a look in the OpenGL ES 2.0 Reference concerning glBindAttribLocation. You have to bind the locations before linking the program. Now it works perfectly the same on Android as on PC.