Results 1 to 3 of 3
  1. #1
    K^2's Avatar
    Join Date
    Jun 2013
    Gender
    male
    Posts
    35
    Reputation
    10
    Thanks
    1,199
    My Mood
    Doubtful

    How to display and FPS counter in the top right corner of a game (Similar to Fraps)

    Hi guys,

    I'm wanting to know how to display an FPS counter in the top right of the screen when a game is being played.
    I've looked for tutorials online but there aren't many and they're not recent plus I have no idea where to get "SDL.h" from.
    I'd like to implement it into a .dll and inject it into the game.
    I'm looking for the basic idea of an FPS counter, any information on how Fraps goes about doing it would be great too!
    I'd prefer the FPS counter like that of Fraps where it constantly displays the framerate.

    Note: I don't want any full source code, only snippets or information on how to attempt it (the steps I should take?), I prefer to learn myself.

    Thanks in advance, appreciated!

  2. #2
    atom0s's Avatar
    Join Date
    May 2013
    Gender
    male
    Posts
    403
    Reputation
    139
    Thanks
    104
    It depends on the game you are injecting into, since the way you are going to draw onto the screen matters on the rendering engine the game is using.

    Fraps has several hooks internally that will attach to the proper functions based on what the game is currently using. Which includes:
    - Direct3D8
    - Direct3D9
    - Direct3D10/11
    - OpenGL

    And so on, (they don't have a full list of what engines are supported but yea..)

    Taking Direct3D8/9 as an example, you'd need to hook at least 'EndScene' in order to do your calculations and drawing. Also keep in mind if you only hook EndScene any textures and objects you create must be marked as 'D3DPOOL_MANAGED' or you will have to hook 'Reset' as well and handle recreating your objects when the device is lost.

    So once you have your hooks, you'll need to create a text object to draw with, and some counter code to handle the FPS calculations.

    The calculation is fairly simple, since EndScene can be called multiple times per-scene, per-second you need to monitor for the time difference and not depend only on the call count to the function.

    Code:
    int m_FPS;
    int m_Count;
    unsigned long m_StartTime;
        
    HRESULT __stdcall MyEndSceneHook( )
    {
        m_Count++;
        
        if (timeGetTime() >= (m_StartTime + 1000))
        {
            m_FPS       = m_Count;
            m_Count     = 0;
            m_StartTime = timeGetTime();
        }
        
        // Draw the fps here..
        
        return m_OriginalDevice->EndScene();
    }
    You can also use the query performance API if you want a high resolution timer with more accuracy.
    - Gone; this is another shit forum with children as administrators. Not worth contributing to.

  3. The Following User Says Thank You to atom0s For This Useful Post:

    _PuRe.LucK* (06-19-2013)

  4. #3
    I'm not lazy, I just really enjoy doing nothing.
    Donator
    _PuRe.LucK*'s Avatar
    Join Date
    Apr 2013
    Gender
    male
    Location
    idk bruh.
    Posts
    521
    Reputation
    71
    Thanks
    5,650
    My Mood
    Bored
    Quote Originally Posted by atom0s View Post
    It depends on the game you are injecting into, since the way you are going to draw onto the screen matters on the rendering engine the game is using.

    Fraps has several hooks internally that will attach to the proper functions based on what the game is currently using. Which includes:
    - Direct3D8
    - Direct3D9
    - Direct3D10/11
    - OpenGL

    And so on, (they don't have a full list of what engines are supported but yea..)

    Taking Direct3D8/9 as an example, you'd need to hook at least 'EndScene' in order to do your calculations and drawing. Also keep in mind if you only hook EndScene any textures and objects you create must be marked as 'D3DPOOL_MANAGED' or you will have to hook 'Reset' as well and handle recreating your objects when the device is lost.

    So once you have your hooks, you'll need to create a text object to draw with, and some counter code to handle the FPS calculations.

    The calculation is fairly simple, since EndScene can be called multiple times per-scene, per-second you need to monitor for the time difference and not depend only on the call count to the function.

    Code:
    int m_FPS;
    int m_Count;
    unsigned long m_StartTime;
        
    HRESULT __stdcall MyEndSceneHook( )
    {
        m_Count++;
        
        if (timeGetTime() >= (m_StartTime + 1000))
        {
            m_FPS       = m_Count;
            m_Count     = 0;
            m_StartTime = timeGetTime();
        }
        
        // Draw the fps here..
        
        return m_OriginalDevice->EndScene();
    }
    You can also use the query performance API if you want a high resolution timer with more accuracy.

    Thanks helped ^^

Similar Threads

  1. teach you how to glitch and put you in the glitches
    By 97superlink in forum CrossFire Glitches
    Replies: 5
    Last Post: 12-17-2011, 09:22 AM
  2. [HELP] How do i add a name to the hack so it shows in game?
    By ®Jack in forum Combat Arms Hack Coding / Programming / Source Code
    Replies: 11
    Last Post: 07-31-2010, 03:32 AM
  3. Name of the hack in the top left corner?
    By ShoopdaWhoop in forum Combat Arms Hack Coding / Programming / Source Code
    Replies: 5
    Last Post: 07-22-2010, 02:07 AM
  4. Replies: 0
    Last Post: 10-27-2008, 12:52 PM
  5. TUT ON HOW TO DOWNLOAD JAP Soldier Front AND SIGH UP ON THE WEBSITE
    By the1fear in forum Soldier Front General
    Replies: 13
    Last Post: 04-28-2008, 04:45 PM

Tags for this Thread