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
    Posts
    4

    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 :
    //Clear
    glClearColor(0.25, 0.0, 0.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    //Configure viewport
    glViewport(0, 0, this->width, this->height);
     
    //Update matrices
    this->baseShader.bind();
    this->baseShader.updateProjectionMatrix(this->matrix);
    this->matrix.loadIdentity();
    this->baseShader.updateModelViewMatrix(this->matrix);
     
    //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);
    glEnableVertexAttribArray(0);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
     
    glDisableVertexAttribArray(0);
     
    //.....

    The results are following:

    TextureComparison1.jpg

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

    Code :
    //.....
     
    //Enable blending
    bw::Texture::enableAlpha();
     
    //Matrices
    this->textureShader.bind();
    this->textureShader.updateProjectionMatrix(this->matrix);
    this->matrix.loadIdentity();
     
    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);
     
    this->textureShader.updateModelViewMatrix(this->matrix);
     
    //Coordinates
    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);
    glEnableVertexAttribArray(0);
     
    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, texCoords);
    glEnableVertexAttribArray(1);
     
    //Bind texture
    int u1 = glGetUniformLocation(this->textureShader.getId(), "u_Texture");
    glActiveTexture(GL_TEXTURE0);
    this->spriteTexture.bind();
    glUniform1i(u1, 0);
     
    //Draw
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
     
    glDisableVertexAttribArray(0);
    glDisableVertexAttribArray(1);

    But this gives me different results:

    TextureComparison2.jpg

    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
    Posts
    4
    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.

Similar Threads

  1. Replies: 6
    Last Post: 03-08-2018, 11:51 AM
  2. Android 3D Item not well displayed
    By romainb in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-06-2017, 01:36 AM
  3. textures displayed inverted
    By sorflex in forum COLLADA
    Replies: 1
    Last Post: 01-09-2008, 06:04 PM
  4. textures not displayed after converting from .flt to opengl
    By sujudavid in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 11-24-2004, 08:14 PM
  5. lookups on incomplete textures
    By zen in forum OpenGL: GLSL
    Replies: 13
    Last Post: 09-27-2004, 09:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean