# Thread: OpenGL complex texture mapping

1. ## OpenGL complex texture mapping

Hey.
Still working on the Sudoku game adding in menu options and custimizable backgrounds (ect). I added all the menu items into the game using a sprite sheet just so I could get used to texture mapping different sized shapes (I figured this was going to be important when I started having high poly count objects in a game, and this was a experiment to get around the power of 2 restriction.. accessing a part of the picture that isn't in a power of 2 while the picture itself is). Everything seems to work all right but I do get some white lines in the texture map (because the items are surrounded by white lines to fix this I changed the lines to black since the objects blended to black).
Important note: These are squares I'm working with.. I wanted to get them right before I switched to using two triangles.

While its an acceptable solution for this situation I would rather understand why I wasn't fully acurate.
How I approached this problem.
I use paint to make all my textures (cause I'm broke), and therefore used pixel reference points to where the map will start and where it will stop. Given I know a picture 1024/1024 will have a conversion rate to the float texture map points. This conversion rate can be calculated as.

conversionratio = maxtexture(1.0f)/maxpixels(1024)

Then I used that conversion ratio to map the texture having a function
Code:
`Object.SetTexCoords(topleftx, toplefty, w, h);`
Since width and height can calculate the bottomrightx and y texture coordinates.

To get the values of topleftx, toplefty, w and h converted from its pixel values which are easy to find in microsoft paint i used
Code:
```topleftx = topleftxpixel * conversionratio;
toplefty = 1.0f - (topleftypixel * conversionratio);
// because the top of a picture in pixels is 0, and in textures its 1.0f so I had
// to swap the directions hence the 1.0f - (number);
w = pixelw * conversionratio;
h = pixelh * conversionratio;```
Is my inacuracy because I'm using floats and the ratio of 1024 to 1 becomes a long decimal? Should I maybe use doubles, or smaller pictures possibly no larger than 256?

Is my method itself internally flawed in a way that anyone notices?

2. Your texture coordinates should stretch from (topleftx, toplefty) in the upper left corner and (topleftx + w - 1, toplefty + h - 1) in the bottom right, otherwise you will include the white/black border.

3. Cool thank you for the response. I don't see this being a problem when I move to triangles, but I was just curious as to why I was getting white lines. For some reason I should have realized to subtract 1 pixel from the height and width. Though not EVERY quad actually showed a white line on the bottom and right as would be expected from your description, but my guess on that is because the adjacent quads covered up those parts and the overlap made the white lines go away.

4. You probably want to move your texture coordinates by 1 texel.

1.0f / TextureWidth;
1.0f / TextureHeight;

5. When you say 1.0f / texture width... do you mean the width of the entire picture you are using as a texture? Or do you mean the width of the area within the picture you are using as your current texture?

Sorry to pose another question, but my google searches turned up alot about a city in amesterdam and a small stub in wiki that I didn't fully wrap my head around. I get that a texel is apparently the equivalent of 1 pixel within a texture aka a TEXture pixEL. Originally when I read that I thought that my conversionratio was already making a texel.
1024 = picturewidth
and
conversionratio = 1.0f/1024

but then I thought.. I could be compeletely wrong if by texture width you mean the "relative" texture I'm accessing within the picture. Say I was working with a 1024 pixel picture, but my current texture target is only 230x 230 (still thinking in quads sorry) would the texel of this texture be

1.0f/1024

or would it be

1.0f/230

if the latter is the case it almost seems like more work would be required when it came to locatating where that object was located within a picture with a different ratio than the texture itself has.