Everything you need to create a game with FRAG

Documentation is still very much a work in progress. Please understand there may be rapid changes to this section of the website.

Documentation Progress: 5%

The Implementation

How FRAG does it

FRAG’s game loop is pretty standard and can be broken down into several sections.


Let’s get things started…

The initialization phase of the game loop begins when the startFrag procedure is called.

Engine Code

  proc startFrag*T =
    var ctx = Frag()
    ctx.init(config, app)
Example Game Code

  proc initApp(app: App, ctx: Frag) =
    # Application initialization logic goes here!

startFrag(App(), Config( rootWindowTitle: “Frag Example 00-hello-world”, rootWindowPosX: window.posUndefined, rootWindowPosY: window.posUndefined, rootWindowWidth: 960, rootWindowHeight: 540, resetFlags: ResetFlag.VSync, logFileName: “example-00.log”, assetRoot: “../assets”, debugMode: BGFX_DEBUG_TEXT ))

During this phase of the game loop, the framework itself along with all of its subsystems will be initialized. The initApp procedure of the app object provided to the startFrag procedure, will also be invoked - allowing the FRAG application to execute whatever initialization logic it needs to.


Your game logic goes here!

Once the framework, subsystems, and application have all finished carrying out their initialization logic, the game loop actually begins.

During every iteration of the game loop, the updateApp procedure will be called. This provides the application with a hook where it can implement whatever update logic it needs to.

Example Game Code

  proc updateApp(app:App, ctx: Frag, deltaTime: float) =
    # Update application state here!


Ready. Set. Draw.

Along with the updateApp procedure, the renderApp procedure will be called each frame. Similar to how application state updates should be performed during the updateApp invocation, any drawing that is to be done should be performed during this call.

Example Game Code

  proc renderApp(app: App, ctx: Frag, deltaTime: float) =
    # Clear Color & Depth Buffers, ClearMode.Color.ord or ClearMode.Depth.ord, 0x303030ff, 1.0, 0)
    # Perform application rendering here!


Don’t forget to clean up after yourself!

The final phase of the game loop is the shutdown phase. This phase is entered when the framework calls the shutdownApp procedure.

For this phase to be entered, the conditional check which was enforcing the actual loop of the game loop, must fail. This is generally caused by the end-user of the application closing it, or the application unexpectedly terminating.

During the invocation of the shutdownApp procedure, resources which are not automatically released by the framework, or garbage-collected, should be freed.

Example Game Code

  proc shutdownApp(app: App, ctx: Frag) =
    # Free resources here!