Hello, Im trying to load a sequence of images that are stored in a 256x256 texture. Suppose each image is 64x64 and in the
texture are 16 images. Im taking an approach similar to when drawing fonts. My problem is that when I draw one of the
images in the upper row, there is always a little pixel (or less than a pixel!) from the above row and/or from the under
row. Im almost sure the problem is when calculating the texture coords but I couldnt find it. Here is a short part
of my code, tell me if you know what Im missing / doing wrong.
if (CurrentFrame >= TotalFramesNum) {
CurrentFrame = 0;
}
TextureWidth = 256;
FrameWidth = 64;
// now calc the coords
cx = float(int( CurrentFrame ) % 4) / 4;
cy = float(int( CurrentFrame ) / 4) / 4;
And later, to draw the quad with the frame:
glBegin(GL_QUADS);
glTexCoord2f(cx, 1 - cy);
glVertex3f(m_PosX,m_PosY,0);
glTexCoord2f(cx + (FrameWidth / TextureWidth ), 1 - cy);
glVertex3f(m_PosX + m_Width,m_PosY,0);
glTexCoord2f(cx + (FrameWidth / TextureWidth ),1 - cy - (FrameWidth /TextureWidth ));
glVertex3f(m_PosX + m_Width,m_PosY + m_Height,0);
glTexCoord2f(cx, 1 - cy - (FrameWidth / TextureWidth ));
glVertex3f(m_PosX,m_PosY + m_Height,0);
glEnd();
This is all I have. Thanks in advance.