I am new to OpenGL and am currently trying to render a cube with four faces, each with a different texture.
As you all know, having a separate texture for each face type is very memory intensive and makes the application slow.
I'm currently trying to use a texture sheet for a sprite. I have a graphic file with each texture 16x16 pixels with 256 sprites squared (16x16).
I know that
GL11.glTexCoord2f(1.0f, 0.0f); GL11.glVertex3f(1.0f, 1.0f, 1.0f); GL11.glTexCoord2f(0.0f, 0.0f); GL11.glVertex3f(0.0f, 1.0f, 1.0f); GL11.glTexCoord2f(0.0f, 1.0f); GL11.glVertex3f(0.0f, 0.0f, 1.0f); GL11.glTexCoord2f(1.0f, 1.0f); GL11.glVertex3f(1.0f, 0.0f, 1.0f);
gives me a rectangle with the entire sprite sheet, so u and v glTexCoord2f have less than 1.0f.
Now I need a formula that will calculate u and v any sprite id in the texture.
The raster identifiers of the texture are as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 16 20 21 22 23 24...
and I would like to have u and v for any of these identifiers. The last bit is not explained very well, so I will explain it better if you want.
Thank you in advance!
source share