Skip to main content
gamedev.net
🔒 Locked

Show FPS

Started by Kacke Oct 15, 2000 at 12:39 PM 0 replies 400+ views
Original Post
Kacke
Kacke
Anyone know an good code for showing the FPS in OpenGL?? I''ve an old and bad code I wrote for DirectX but it only shows the FPS divideable with five (5, 10, 15 and so on) Please help me / Markus Svensson
Jallen
Jallen
Put this

SetTimer(hWnd, 1, 1000, nil); // Timer fire''s every 1000
// milliseconds (1 second)

Inside of the WM_CREATE window message (inside the WndProc function so that the timer is created when the program starts, like this:

WM_CREATE:
begin
SetTimer(hWnd, 1, 1000, nil);
end;

Then create a variable called numFrames and increment it at the end of your DrawGLScene (or equivalent) function.

now every second your window will recieve a WM_TIMER message so you need to catch it and handle it like this:

WM_TIMER:
begin
// Display numFrames somewhere on screen then set it to
// zero
DrawFPS(); // Some function you create that displays the FPS
numFrames := 0;
end;

What this code does is every second it checks how many times you have redrawn your scene (number of times DrawGLScene was executed), displays this number then resets the frame counter and continually updates your FPS every second.

The only problem with this is that the window timer (WM_TIMER) isn''t very accurate but if you are just using this for a rough idea of the number of frames per second you are getting its a quick and easy way to do it.

Jason A.

---
I write code.
DelphiGL (members.home.com/jra101)
---I write code.DelphiGL (http://delphigl.cfxweb.net)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.