Application
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.
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()
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.
Name | Type | Description |
---|---|---|
antialiasing | int | Antialiasing level (e.g., 4x MSAA). |
clear_color | Color | Background clear color. |
height | int | Window height in pixels. |
show_stats | bool | Show stats UI overlay. |
title | std::string | Window title. |
vsync | bool | Enables vertical sync. |
width | int | Window width in pixels. |
Functions
Configure() Parameters virtual
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.
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.
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.
Camera * vglx::Application::GetCamera() const
Returns the current camera pointer.
GetContext() SharedContextPointer
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.
Scene * vglx::Application::GetScene() const
Returns the current scene pointer.
SetCamera() void
void vglx::Application::SetCamera(std::shared_ptr< Camera > camera)
Parameter | Description |
---|---|
camera | Shared pointer to the new camera. |
Sets the active camera.
SetScene() void
void vglx::Application::SetScene(std::shared_ptr< Scene > scene)
Parameter | Description |
---|---|
scene | Shared pointer to the new scene. |
Sets the active scene.
Start() void
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
virtual bool vglx::Application::Update(float delta)=0
Parameter | Description |
---|---|
delta | Time 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.