The libavg app module provides a basis for writing applications. It handles window setup and global keyboard handling, handles global application settings, and provides a number of debugging aids. The two main classes in the app module are App itself and MainDiv. The reference to the module is at https://www.libavg.de/reference/svn/app.html.

This program already supports configuration of global parameters (start using ./app.py -h for a list of command line parameters) and a number of debugging keys (press '?' during program execution to get a list of supported keys). Note that we're overriding app.MainDiv here. You usually don't need to override avg.App. The example also shows you the three main method overrides onInit, onExit and onFrame.

The App class has two ways of setting global parameters such as the size of the application window. First, parameters can be set when calling App.run():

1app.App().run(MyMainDiv(), app_resolution='1024x500')

Second, they can be passed to the program on the command line:

1$ python app_minimal.py --app-resolution=1024x500

As you can see, spelling of the parameters is adapted according to the method of setting them: In run parameters, words are separated using underlines, and in command line parameters, they are separated using dashes. If parameters are defined in more than one fashion, environment variables take precedence over App.run() parameters, and command line parameters take precedence over both other forms.

Here is a more complete example of using the app module. The following program shows a moving rectangle. It also handles additional command-line parameters and installs a key handler that allows you to turn the animation on and off:

Pressing 'ctrl-f' shows a graph that displays the time per frame for the last few seconds of execution. Here is an example:

Note the bar graph at the right. The bars show how the frame times were distributed while the graph was active: The leftmost bin shows all frames that took less than 20ms, the second bin is limited to 40ms, etc. A non-jittery application should show a nearly flat line at the 17ms mark and a bar graph that is empty in all but the leftmost bin.

In contrast to the Frame Time Graph, this graph is rescaled continuously so it displays all memory usage changes that happen while the graph is displayed. The top of the graph is also scaled so it corresponds to the maximum memory usage. So, to find memory leaks, press 'ctrl-m' and leave the graph on while interacting with the applications. You will immediately see at which points in time the memory usage goes up (or fails to go down). Some caution is advised, however, since Python heap management and garbage collection tend to reclaim memory at non-deterministic points in time.

An additional graph, the GPU Memory Graph, can be activated by pressing 'ctrl-g' on Linux and Windows systems with NVidia graphics. It shows the amount of graphics card memory being used - e.g. by textures.

To help narrow down memory leaks, it is possible to show a table of allocated objects of various types by pressing 'ctrl-o'. The table contains a row of data per libavg class and shows the number of currently allocated objects of each class in the rightmost column. Pressing 'ctrl-i' causes a snapshot of the data to be taken and displayed to the left of the current data, so you can compare object counts at different points in time easily.