Getting Frame Rate in DirectX

This is a discussion on Getting Frame Rate in DirectX within the Game Programming forums, part of the General Programming Boards category; I was wondering what is the best to get the frame rate. I saw many differnet ways of doing it ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    Getting Frame Rate in DirectX

    I was wondering what is the best to get the frame rate. I saw many differnet ways of doing it but the one I know how to do is using the windows timers, like SetTimer(). But I'm not sure if that is a good way or the best way.

    EDIT: Also were should my drawing events for d3d go? I have them in the loop were you translate the windows messages but that seems to lag horibly, even freeze at times.

    thanks
    Last edited by Rune Hunter; 11-01-2005 at 05:17 PM.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    Inside of you main loop you call Render() and pass the frame time delta for that frame.
    Code:
    //
    // WinMain
    //
    int WINAPI WinMain(HINSTANCE hInstance,
    				   HINSTANCE prevInstance, 
    				   PSTR cmdLine,
    				   int showCmd)
    {
      //Create window for app
       if(!g_ZeldaApp.InitD3D(hInstance,
    		                     WIDTH, 
                             HEIGHT, 
                             false, 
                             D3DDEVTYPE_HAL,
                             &g_pDevice))
    	{
    		::MessageBox(0, "InitD3D() - FAILED", 0, 0);
    		return 0;
    	}
    	
       if(!Setup())
    	{
    		::MessageBox(0, "Setup() - FAILED", 0, 0);
    		return 0;
    	}
      
      g_ZeldaApp.EnterMsgLoop(Display);
    
    	
      //We are done so clean up the memory and COM objects
      Cleanup();
      
      //Give our device back to COM
      g_pDevice->Release();
      
      return 0;
    }
    Code:
    int CD3DApp::EnterMsgLoop(bool (*DisplayFunc)(float timeDelta))
    {
    	MSG msg;
    	::ZeroMemory(&msg, sizeof(MSG));
    
    	static float lastTime = (float)timeGetTime(); 
    
    	while(msg.message != WM_QUIT)
    	{
    		if(::PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
    		{
    			::TranslateMessage(&msg);
    			::DispatchMessage(&msg);
    		}
    		else
        {	
    			float currTime  = (float)timeGetTime();
    			float timeDelta = (currTime - lastTime)*0.001f;
    
    			DisplayFunc(timeDelta);
    
    			lastTime = currTime;
        }
      }
        return msg.wParam;
    }
    That's how I've set mine up. There are other ways to do it.

    Display is a function pointer that points to Render().
    Last edited by VirtualAce; 11-02-2005 at 02:30 AM.

  3. #3
    ---
    Join Date
    May 2004
    Posts
    1,379
    Bubba, I just recognised that code from the book I just started reading.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    Yep it works fairly well too so I figured if it wasn't broke, why fix it? However, I did encapsulate everything inside of a class instead of just using namespaces and I've added audio, input, texture, memory, and other resource initialization to the app.

    Good book but some of the ways he does things is not the best IMO.

    The sample framework in D3D looks a bit like this as well.

  5. #5
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    thanks alot, that looks perfect.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Animation not working....
    By aquinn in forum C Programming
    Replies: 7
    Last Post: 02-19-2005, 04:37 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. Frame Rate
    By Tommaso in forum Game Programming
    Replies: 6
    Last Post: 04-04-2003, 05:40 PM
  4. Lock Frame Rate??
    By Unregistered in forum Game Programming
    Replies: 1
    Last Post: 06-06-2002, 11:03 PM
  5. Whats a good frame rate?
    By compjinx in forum Game Programming
    Replies: 16
    Last Post: 04-07-2002, 05:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21