Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Textures larger and incomplete displayed on Android OpenGL ES 2.0

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2014

    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":

    Code :
    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:

    Click image for larger version. 

Name:	TextureComparison1.jpg 
Views:	319 
Size:	10.1 KB 
ID:	1620

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

    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:

    Click image for larger version. 

Name:	TextureComparison2.jpg 
Views:	250 
Size:	10.8 KB 
ID:	1621

    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?

  2. #2
    Junior Member Newbie
    Join Date
    Jul 2014
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts