Texture Coordinate Help

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

Texture Coordinate Help

Postby general_bradley » Thu Mar 18, 2010 4:27 am

This is a somewhat follow-up from my previous post about Icosahedrons, I can draw them now, but I'm having difficulties texturing them.

I read that textures need to have dimensions in powers of 2, so I made a simple 256x256 texture with a bunch of numbers (to help with debugging). I understand that the texture coordinates need to be from 0.0 - 1.0 (anything less/greater will result in clamping based on the rules established). I took a look at the pixel information for a particular triangle (specifically, triangle number 1, in numbers.png) and found the 3 vertices to be (from the top left):

25,5 (top)
2,44 (bottom left)
49,44 (bottom right)

And to convert these into values from 0 - 1, I divide each point by 256 (the width and height of the texture), and get:

0.097656f, 0.019531f (top)
0.007813f, 0.171875f (bottom left)
0.191406f, 0.171875f (bottom-right)

However, as you can see by the texture-test.jpg, it doesn't quite map it properly (I added the red triangle to emphasize error). I tried rearranging the order of the coordinates as well as changing the rendering to clock-wise, but no combination of either of the two modifications made any improvement (and in most cases, made it worse).

I've included the Icosahedron file I'm using incase anyone wanted to try it and see if they get the same results I'm using. Any help would be appreciated.
(6.03 KiB) Downloaded 180 times
number.png (45.47 KiB) Viewed 967 times
texture-test.jpg (93.76 KiB) Viewed 967 times
Posts: 8
Joined: Wed Feb 24, 2010 7:40 am


Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests