[CSC 415] FPS

Andrew J. Pounds pounds_aj at mercer.edu
Sun Mar 5 02:50:03 EST 2023


Yesterday was interesting.  I woke up thinking about graphics.  On 
Thursday and Friday I was struggling with how to implement proper timing 
in our graphics programs because simply displaying the FPS in the 
terminal window was forcing a callback to the screen driver - which 
would be locked at 60 FPS.  To get things like I wanted them I would 
have to do all of the FPS timing INSIDE of the graphics without the use 
of printf to the screen.  In my mind that meant having to display the 
FPS inside the graphics window -- which brought me back to the familiar 
problem of how to get the text to show up in the window.

Getting the text to show up in the window is something I have done 
before - but it took a lot of work and I wasn't necessarily ready to 
throw that at you.  Without this ability, however, it was going to be 
impossible for you to get really good actual timings off of your code 
and synch it properly to the physics.

So on Saturday morning, around 10 am, I went into "Monk Mode" - which 
means I closed myself off in my study, turned on some classical music, 
dug out all my OpenGL reference manuals, and solved the problem.  It 
took until about 3 pm - but it did not seem like it at all.  For those 
of you that took CSC 330 -  I was in "flow".  I also have to give a 
shoutout to Eduardo Luciani who wrote a newer tutorial combining OpenGL 
4.6 and FreeType 2 (all of my prior code used much earlier versions of 
GL and was MUCH more complicated).  His tutorial helped me take some 
shortcuts that I can pass on to you.   To make all this little easier 
for you to digest - I tried to break my solution up into code pieces 
that you can implement in your own code.  These are:

 1. void buildFonts()  - build the font cache in memory from the Arial
    TrueType font using the FreeType2 library.  This needs to be called
    in "init" or else it cuts the framerate by roughly a factor of 20 (I
    tried it both ways)
 2. std::string showFPS() - to calculate the FrameRate on the fly using
    glfwGetTime function (still checking the
    granularity/accuracy/reproducibility)
 3. void doOrthoGraphics() - called in the display function after all of
    the 3D work to:
      * Load two new ORTHOGRAPHIC oriented vertex and fragment shader
        programs
      * Set up new texture based buffers for the graphics card
      * Set up a 2D orthographic projection on a portion of the screen
      * Calculates the frame rate using showFPS
      * Writes the FPS string to an OpenGL Texture object using the font
        cache created in buildFonts
      * Display the texture in the orthographic window

I'm still working to repackage all of this for you (more comments as 
well as describing what new structs and global variables have to 
defined) and I have yet to test my lock for the framerate so we can 
synch to the physics, but it all seems to be working and I'm getting 
roughly 4000 FPS off of my NVidia GTX.  I'll keep you posted on the 
progress.



-- 
*/Andrew J. Pounds, Ph.D./*
/Professor of Chemistry and Computer Science/
/Director of the Computational Science Program/
/Mercer University, Macon, GA 31207 (478) 301-5627/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://theochem.mercer.edu/pipermail/csc415/attachments/20230305/201e8838/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LbtuVkERpenMGvGn.png
Type: image/png
Size: 8919 bytes
Desc: not available
URL: <http://theochem.mercer.edu/pipermail/csc415/attachments/20230305/201e8838/attachment.png>


More information about the csc415 mailing list