PDA

View Full Version : Animated texture problems.



Anonymous Coward
06-07-2001, 04:12 AM
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.

MButchers
06-07-2001, 04:46 AM
Hello there,

it sounds as if yuo are using
fitering on the texture-the problem is that the filtering is applied to the whole
texture so you end up getting some of the
neighbouring pixels color. Try turning
of filtering to check this out.

Hope this helps a bit.

Anonymous Coward
06-07-2001, 07:18 AM
You're right, I was using bilinear filtering...Now, If I use GL_NEAREST, there is no problem. Do you know if there is a way of using GL_LINEAR without the problems Im getting? (Thanks!)

Korval
06-07-2001, 07:52 AM
Move your texture coordinates inward one half of a pixel. So, if your original texture coords were (0,0) to (1/64, 1/64) on a 256x256 texture, they would become (1/512, 1/512) to (7/512, 7/512).

Anonymous Coward
06-07-2001, 09:07 AM
Thats it...now it works. Thanks.