Skip to content

Application

The runtime entry point for defining and launching an app.

The Application class is the runtime: it 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 (window, renderer, loop, etc.), but that is outside the scope of this runtime API.

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, constructs the user scene (and camera, if provided), then runs the main loop while invoking Update each frame.

Construction

Constructors


Application()

cpp
vglx::Application::Application()

Constructs an Application instance. Initializes internal state but does not start the application loop.

Types

Application::Parameters struct

Configuration parameters for the application context.

NameTypeDescription
antialiasingintAntialiasing level (e.g., 4x MSAA).
clear_colorColorBackground clear color.
heightintWindow height in pixels.
show_statsboolShow stats UI overlay.
titlestd::stringWindow title.
vsyncboolEnables vertical sync.
widthintWindow width in pixels.

Functions

Configure() Parameters virtual

cpp
virtual Parameters vglx::Application::Configure()

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.

CreateCamera() std::shared_ptr<Camera> virtual

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

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

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

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

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

GetCamera() Camera*

cpp
Camera * vglx::Application::GetCamera() const

Returns the current camera pointer.

cpp
SharedContextPointer vglx::Application::GetContext() const

Returns a pointer to current active shared context. The shared context holds runtime parameters (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.

GetScene() Scene*

cpp
Scene * vglx::Application::GetScene() const

Returns the current scene pointer.

SetCamera() void

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

Sets the active camera.

SetScene() void

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

Sets the active scene.

Start() void

cpp
void vglx::Application::Start()

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

Update() bool pure virtual

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

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.

Released under the MIT License.