Thread: Animate texture and FPS

  1. #1
    Computer guy
    Join Date
    Sep 2005
    Location
    I'm lost!!!
    Posts
    200

    Animate texture and FPS

    Somehow FPS still confuses me, and here is my problem:

    After loading and store a sequence of texuture, i draw the quad including the texuture (This a general code, not the code i implement in my program):
    Code:
    void Draw()
    {
    glBindTexture(GL_TEXTURE_2D, AnimateTexture[frameCount]);
    //draw the quad
    
    frameCount++;
    if ( frameCount == MaxTexture )    // if frameCount equal to max index of the sequence
    frameCount = 0;
    
    }
    The thing is, when i run it, the sequence of texture draw really fast. I want to limited the speed drawing down to 30fps. How can i do it?
    Hello, testing testing. Everthing is running perfectly...for now

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    An example of an animation update function.

    Code:
    DWORD CAnimSeq::Update(float fDelta)
    {
      //Advance time by delta
      m_fElapsed+=fDelta;
        
      //Check whether or not to advance
      if (m_fElapsed>=m_fMSPerFrame)
      {
        //Find out how many frames to advance
        DWORD dwAdvanceBy=static_cast<DWORD>((m_fElapsed/m_fMSPerFrame));
        
        //Decrement elapsed time to compensate
        m_fElapsed-=(dwAdvanceBy*m_fMSPerFrame);
      
        //Advance frame
        m_dwCurFrame+=dwAdvanceBy;
        
        //Check if we are at the end of the sequence or past it
        if (m_dwCurFrame>=m_vFrames.size())
        {
          if (m_bLooped)
          {
            //Since we are looped, advance to 0, or past 0 depending on current frame
            m_dwCurFrame-=static_cast<DWORD>(m_vFrames.size());
          } 
          else 
          {
            m_bActive=false;  //else de-activate animation
            m_dwCurFrame=static_cast<DWORD>(m_vFrames.size())-1;
          }
        }
      }
     
      //Return current frame to caller
      //Useful inside of an animation loop so another call is not required to get
      //current animation frame ID
      return m_vFrames[m_dwCurFrame];
    }
    fMSPerFrame is calculated by:

    Code:
    void CAnimSeq::Create(float fFPS,bool bLooped)
    {
      m_fFPS=fFPS;
      m_fElapsed=0.0f;
      m_bLooped=bLooped;
      m_fTotalSeconds=1000.0f/m_fFPS;
      m_fMSPerFrame=0.0f;
    }
    
    DWORD CAnimSeq::AddFrame(DWORD dwFrameID)
    {
      m_vFrames.push_back(dwFrameID);
      m_fMSPerFrame=(m_fTotalSeconds*1000)/m_vFrames.size();
      return static_cast<DWORD>(m_vFrames.size()-1);
    }
    Each frame is simply a texture ID that resolves to a certain texture in the texture manager vector. All texture access is via the texture manager public functions. So my animation system is iterating through a vector of DWORD values over a specified amount of time.

  3. #3
    Computer guy
    Join Date
    Sep 2005
    Location
    I'm lost!!!
    Posts
    200
    I see, as for the fDelta in the Update function, what would its value be? would it be another calculation? As far as i understand, this is what i get out from your code:
    Code:
    //run the bindTexture with the default frame = 0
    
    counter++;
    if ( counter > 30 )
    {
      frame++;
      counter = 0;
    }
    
    if ( frame > max_frame)
    frame = 0;
    Hello, testing testing. Everthing is running perfectly...for now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  2. the effects of textures on my frame rate
    By DavidP in forum Game Programming
    Replies: 37
    Last Post: 10-03-2003, 11:24 AM
  3. FPS Counter Prob in OpenGL
    By brandonp in forum Game Programming
    Replies: 1
    Last Post: 07-16-2002, 02:49 PM