Skip to content

Application

The runtime entry point for defining and launching an app.

The runtime sets up the window, rendering context, a main loop, and calls your hooks. Subclass it and override Configure, CreateScene, and Update to define behavior.

This is the preferred way to initialize a new app. If you need complete control, you can also assemble a program manually.

cpp
class MyApp : public vglx::Application {
 public:
  auto Configure() -> Application::Parameters override {
    return {
      .title = "My App",
      .width = 1024,
      .height = 768,
      .clear_color = 0x444444,
      .vsync = true,
      .show_stats = true
    };
  }

  auto CreateScene() -> std::shared_ptr<vglx::Scene> override {
    auto scene = vglx::Scene::Create();
    // Add nodes to the scene...
    return scene;
  }

  // Optional: override CreateCamera() to provide your own camera.
  // Returning nullptr creates a default perspective camera.
  // auto CreateCamera() -> std::shared_ptr<vglx::Camera> override { ... }

  auto Update(float delta) -> bool override {
    // Per-frame logic. Return false to exit the main loop.
    return true;
  }
};

int main() {
  MyApp app;
  app.Start();
  return 0;
}

Calling Start initializes the runtime, sets the active user scene and camera, then runs the main loop while invoking Update each frame.

Types

Application::Parameters struct

Parameters for configuring an application object.

These values are not passed directly to the constructor. To override the defaults, implement the Configure function and return an instance with customized settings.

ParameterDescription
title std::stringWindow title.
clear_color ColorBackground clear color.
width intWindow width in pixels.
height intWindow height in pixels.
antialiasing intAntialiasing level (e.g., 4x MSAA).
vsync boolEnables vertical sync.
show_stats boolShow stats UI overlay.

Functions

Configure() Parameters virtual

Provides configuration parameters for the application.

Override this method to customize window settings, clear color, antialiasing, vsync, and other runtime options before the application starts.

cpp
virtual Parameters Application::Configure();

CreateCamera() std::shared_ptr<Camera> virtual

Creates the main camera.

This method can be optionally overridden. If null is returned, a default perspective camera will be created automatically.

cpp
virtual std::shared_ptr<Camera> Application::CreateCamera();

CreateScene() std::shared_ptr<Scene> pure virtual

Creates the root scene graph.

This method must be implemented by the user and returns the primary scene used for rendering and updates.

cpp
virtual std::shared_ptr<Scene> Application::CreateScene()=0;

GetCamera() Camera*

Returns the current camera pointer.

cpp
Camera* Application::GetCamera() const;

GetContext() SharedContextPointer

Returns a pointer to current active shared context.

The shared context holds runtime properties (e.g., window size, framebuffer size, aspect ratio, active camera) and provides access to built-in resource loaders. It is created internally during application startup and is guaranteed to remain valid for the lifetime of the application.

cpp
SharedContextPointer Application::GetContext() const;

GetScene() Scene*

Returns the current scene pointer.

cpp
Scene* Application::GetScene() const;

SetCamera() void

Sets the active camera.

cpp
void Application::SetCamera(std::shared_ptr<Camera> camera);
ParameterDescription
cameraShared pointer to the new camera.

SetScene() void

Sets the active scene.

cpp
void Application::SetScene(std::shared_ptr<Scene> scene);
ParameterDescription
sceneShared pointer to the new scene.

Start() void

Starts the application loop.

This method initializes the window, rendering context, and user scene and enters the main loop until the application exits.

cpp
void Application::Start();

Update() bool pure virtual

Per-frame update callback.

This method must be implemented and is called every frame with the elapsed time since the last frame. Return false to exit the main loop and close the application.

cpp
virtual bool Application::Update(float delta)=0;
ParameterDescription
deltaTime in seconds since the last frame.

Released under the MIT License.