1. Dashboard
  2. Getting Started
  3. GitHub
  4. API
  5. Articles
  6. Level Editor
  7. Members
    1. Recent Activity
    2. Users Online
    3. Staff
    4. Search Members
  8. Forum
  9. Discord
  • Login
  • Register
  • Search
Getting Started
  • Everywhere
  • Getting Started
  • Articles
  • Pages
  • Forum
  • More Options
  1. GFX-Engine
  2. Articles
  3. Getting Started

Complete Example: Minimal Game Class

  • Andy
  • January 4, 2026 at 10:13 AM
  • 308 Views
  • 0 Comments

The following example shows a minimal but complete GFX-Next application structure. It demonstrates the essential building blocks required to start and run an application, including engine initialization, application setup, and the main execution loop. The example is intentionally kept small and focused, making it easy to understand how the different parts fit together while still reflecting real-world usage. By studying this structure, developers can quickly grasp the recommended entry points, control flow, and responsibilities within a typical GFX-Next application and use it as a foundation for more complex projects.

Program.cs

C#
using LibGFX.Graphics.Renderer.OpenGL;

namespace GetStarted
{
    internal class Program
    {
        static void Main(string[] args)
        {
            MyGame game= new MyGame();
            game.Run(new GLRenderer());
        }
    }
}
Display More

MyGame.cs

C#
using LibGFX;
using LibGFX.Assets;
using LibGFX.Core;
using LibGFX.Core.GameElements;
using LibGFX.Graphics;
using LibGFX.Graphics.Enviroment;
using LibGFX.Graphics.Lights;
using LibGFX.Graphics.Materials;
using LibGFX.Graphics.Primitives;
using LibGFX.Graphics.Renderer.OpenGL;
using OpenTK.Mathematics;

public class MyGame : Game
{
    private Scene3D _scene;
    private PerspectiveCamera _camera;

    private Mesh _cubeMesh;
    private SGMaterial _defaultMaterial;

    public override void LoadContent(AssetManager assets)
    {
        // Create assets (CPU-side only)
        _defaultMaterial = assets.Add(
            new SGMaterial("DefaultMaterial", new Vector4(0.8f, 0.8f, 0.8f, 1.0f))
        );

        _cubeMesh = assets.Add<Mesh>(
            "CubeMesh",
            Cube.GetMesh(_defaultMaterial)
        );
    }

    public override void Initialize(IRenderDevice renderer)
    {
        // Create camera
        _camera = new PerspectiveCamera(
            new Vector3(0, 3, -6),
            new Vector2(Viewport.Width, Viewport.Height)
        );
        _camera.SetAsCurrent();

        // Create scene
        _scene = new Scene3D();
        _scene.Enviroment = new ProceduralSky();

        // Add light
        _scene.DirectionalLight = new DirectionalLight3D(
            new Vector3(-0.2f, 1.0f, -0.3f),
            new Vector4(1.0f),
            1.0f
        );

        // Add primitive
        var cube = new Primitive("Cube", _cubeMesh);
        cube.Transform.Position = Vector3.Zero;
        _scene.AddGameElement(cube);

        // Initialize scene
        _scene.Init(Viewport, renderer);
    }

    public override void OnStart()
    {
        // Optional final setup before the game loop starts
    }

    public override void Update(float deltaTime)
    {
        _camera.LookAt(Vector3.Zero);
        _scene.UpdatePhysics(deltaTime);
        _scene.Update(deltaTime);
    }

    public override void Render()
    {
        _scene.RenderShadowMaps(Viewport, RenderDevice, _camera);
        _scene.Render(Viewport, RenderDevice, _camera);

        RenderDevice.DrawRenderTarget(_scene.RenderTarget as MSAARenderTarget2D, GLRenderer.Backbuffer);
    }

    public override void OnFrameEnd()
    {
        _scene.EnqueElements();
    }

    public override void Dispose()
    {
        _scene.DisposeScene(RenderDevice);
    }
}
Display More

Final Note

If you understand this example, you understand:

  • how a GFX-Next application starts
  • how assets and scenes interact
  • how the frame lifecycle works
  • where gameplay logic belongs

Everything else builds on top of this.

  • Previous Article Application Structure & Game Loop

Categories

  1. Advanced Tutorial 1
  2. Getting Started 8
  3. Default Category 1
  4. Reset Filter

Partner & Supporter

  1. Privacy Policy
  2. Legal Notice
Powered by WoltLab Suite™