I am trying to use a texture atlas in a game program that I write in C # / OpenGl with the OpenTK library.
I uploaded my texture atlas as a texture in OpenGL (size 256x256), and each fragment is 32x32.
To display the first plate of the atlas, I used this code:
GL.Begin(BeginMode.Quads);
GL.TexCoord2(0, 0); GL.Vertex2(0, 0);
GL.TexCoord2(0.125f, 0); GL.Vertex2((32 * zoom), 0);
GL.TexCoord2(0.125f, 0.125f); GL.Vertex2((32 * zoom), (32 * zoom));
GL.TexCoord2(0, 0.125f); GL.Vertex2(0, (32 * zoom));
GL.End();
0.125 was calculated by dividing 1/8, 8 by the number of tiles in the row / column.
I have no idea how to calculate the coordinates of the second tile in this way! I tried using 0.125 and 0.25 instead of 0 and 0.125 respectively, but that does nothing. I assume you are not allowed to use a value greater than zero for the (EDIT) first (0) texture coordinates?
If someone can help or provide a better way to do this, it will be very appreciated!