OpenGL-ES Texture Atlas. t axis is inverted.

Posted by Feet on Stack Overflow See other posts from Stack Overflow or by Feet
Published on 2010-05-21T02:52:52Z Indexed on 2010/05/21 3:00 UTC
Read the original article Hit count: 456

I'm mapping a texture from my texture atlas to a square on a cube. For some reason, the t axis is inverted with 0 being at the top and 1 being at the bottom. Also, I have to specify the texture coordinates in clockwise order rather than counter-clockwise. I am using counter-clockwise windings. The vertices, indices and texture coordinates I'm using are below.

 float vertices[] = { 
     // Front face
     -width, -height, depth, // 0
     width, -height, depth, // 1
     width,  height, depth, // 2
     -width,  height, depth, // 3

            // Back Face
            width, -height, -depth, // 4
          -width, -height, -depth, // 5
            -width,  height, -depth, // 6
            width,  height, -depth, // 7

            // Left face
            -width, -height, -depth, // 8
            -width, -height, depth, // 9
            -width,  height, depth, // 10
            -width,  height, -depth, // 11

            // Right face
            width, -height, depth, // 12
            width, -height, -depth, // 13
            width,  height, -depth, // 14
            width,  height, depth, // 15

            // Top face
            -width,  height, depth, // 16
            width,  height, depth, // 17
            width,  height, -depth, // 18
            -width,  height, -depth, // 19

            // Bottom face
          -width, -height, -depth, // 20
          width, -height, -depth, // 21
          width, -height, depth, // 22
          -width, -height, depth, // 23
    };

    short indices[] = { 
      // Front   // Back
      0,1,2, 0,2,3,  4,5,6, 4,6,7,
      // Left    // Right
      8,9,10, 8,10,11,  12,13,14, 12,14,15,
      // Top    // Bottom
      16,17,18, 16,18,19, 20,21,22, 20,22,23,
    };


    float textures[] = {
  // Front
  0.0f, 0.0f, 0.25f, 0.0f, 0.25f, 0.25f, 0.0f, 0.25f,
        // Back
     0.25f, 0.0f, 0.50f, 0.0f, 0.50f, 0.25f, 0.25f, 0.25f,
        // Left
     0.50f, 0.0f, 0.75f, 0.0f, 0.75f, 0.25f, 0.50f, 0.25f,
        // Right
     0.75f, 0.0f, 1f, 0.0f, 1f, 0.25f, 0.75f, 0.25f,
        // Top
     0.0f, 0.25f, 0.25f, 0.25f, 0.25f, 0.50f, 0.0f, 0.50f,
        // Bottom
     0.25f, 0.25f, 0.50f, 0.25f, 0.50f, 0.50f, 0.25f, 0.50f,
    };

© Stack Overflow or respective owner

Related posts about android

Related posts about texture-mapping