Application
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.
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.
| Parameter | Description |
|---|---|
| title std::string | Window title. |
| clear_color Color | Background clear color. |
| width int | Window width in pixels. |
| height int | Window height in pixels. |
| antialiasing int | Antialiasing level (e.g., 4x MSAA). |
| vsync bool | Enables vertical sync. |
| show_stats bool | Show 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.
virtual Parameters Application::Configure();Creates the main camera.
This method can be optionally overridden. If null is returned, a default perspective camera will be created automatically.
virtual std::shared_ptr<Camera> Application::CreateCamera();Creates the root scene graph.
This method must be implemented by the user and returns the primary scene used for rendering and updates.
virtual std::shared_ptr<Scene> Application::CreateScene()=0;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.
SharedContextPointer Application::GetContext() const;SetCamera() void
Sets the active camera.
void Application::SetCamera(std::shared_ptr<Camera> camera);| Parameter | Description |
|---|---|
| camera | Shared pointer to the new camera. |
SetScene() void
Sets the active scene.
void Application::SetScene(std::shared_ptr<Scene> scene);| Parameter | Description |
|---|---|
| scene | Shared 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.
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.
virtual bool Application::Update(float delta)=0;| Parameter | Description |
|---|---|
| delta | Time in seconds since the last frame. |