Question

Je mapper une texture de mon atlas de texture à un carré sur un cube. Pour une raison quelconque, l'axe t est inversé avec 0 étant au sommet et 1 étant en bas. Toutes les idées pourquoi cela se passe?

En outre, je dois préciser les coordonnées de texture dans l'ordre des aiguilles d'une montre plutôt que dans le sens antihoraire. J'utilise des enroulements dans le sens antihoraire. Les sommets, les indices et les coordonnées de texture que je utilise sont ci-dessous.

 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,
    };

Ma texture -. Un 256x256 .png créé dans mspaint

texte alt http://www.freeimagehosting.net/uploads/9a87120b99.png

Était-ce utile?

La solution

Alors, après encore plus la recherche sur le web, il semble que OpenGL suppose une image commence au bas scanline, ce qui signifie que vous devez inverser votre y / t coordonnées. Ou utiliser une origine en haut à gauche quand on regarde l'image d'origine.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top