Results 1 to 5 of 5

Thread: Animated texture problems.

  1. #1
    Senior Member Regular Contributor
    Join Date
    Aug 2000
    Posts
    118

    Animated texture problems.

    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.

  2. #2
    Member Contributor
    Join Date
    May 2001
    Location
    Cheltenham,Gloucestershire,England
    Posts
    59

    Re: Animated texture problems.

    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.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Aug 2000
    Posts
    118

    Re: Animated texture problems.

    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!)

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    3,574

    Re: Animated texture problems.

    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).

  5. #5
    Senior Member Regular Contributor
    Join Date
    Aug 2000
    Posts
    118

    Re: Animated texture problems.

    Thats it...now it works. Thanks.

Similar Threads

  1. How make an animated texture? (OpenGL, DevIL, C++)
    By PocketTNT in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 05-21-2016, 12:53 AM
  2. Replies: 1
    Last Post: 11-12-2013, 09:54 AM
  3. Texture not showing on animated model
    By EvanV in forum OpenGL: Basic Coding
    Replies: 14
    Last Post: 10-08-2011, 07:17 PM
  4. animated texture on Polygon
    By blessman11 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 02-28-2011, 03:03 AM
  5. Animated texture co-ordinates
    By captainfreedom in forum COLLADA
    Replies: 5
    Last Post: 01-30-2009, 12:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean