OpenGL-ES Texture Atlas. t axis is inverted
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. Any ideas why this is happening?
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,
};
My texture - a 256x256 .png file created in mspaint.
alt text http://www.freeimagehosting.net/uploads/9a87120b99.png
So after yet more searching on the web, it seems that OpenGL assumes an image starts at the bottom scanline, meaning that you need to invert your y/t coordinates. Or use an upper left hand origin when looking at your original image.
精彩评论