Documentation

Hesper.GLFW

GLFW Safe API #

Safe GLFW bindings with automatic resource management using Lean.External.

This module provides a clean API for GLFW resources. All resources are automatically cleaned up by Lean's GC when they go out of scope.

Usage Example #

import Hesper.GLFW
import Hesper.WebGPU.Device

def main : IO Unit := do
  -- Initialize GLFW
  withGLFW do
    -- Create window (automatically cleaned up when out of scope)
    let window ← createWindow 800 600 "Hesper Window"

    -- Get device
    let device ← getDevice

    -- Create surface (automatically cleaned up)
    let surface ← createSurface device window

    -- Get preferred format and configure
    let format ← getSurfacePreferredFormat surface
    configureSurface surface 800 600 format

    -- Create shader and pipeline (automatically cleaned up)
    let shader ← createShaderModule device shaderCode
    let pipeline ← createRenderPipeline device shader format

    -- Main render loop
    while !(← windowShouldClose window) do
      renderFrame device surface pipeline
      pollEvents
def Hesper.GLFW.withGLFW {α : Type} (action : IO α) :
IO α

Initialize GLFW with automatic cleanup

Equations
Instances For
    def Hesper.GLFW.createWindow (width height : Nat) (title : String) :

    Create a window. Automatically cleaned up by GC.

    Equations
    Instances For

      Check if window should close

      Equations
      Instances For
        def Hesper.GLFW.getKey (window : Window) (key : Key) :

        Get key state

        Equations
        Instances For

          Create a surface. Automatically cleaned up by GC.

          Equations
          Instances For
            def Hesper.GLFW.configureSurface (surface : Surface) (width height format : Nat) :

            Configure surface dimensions and format

            Equations
            Instances For

              Get preferred surface format

              Equations
              Instances For

                Present surface

                Equations
                Instances For

                  Get current texture. Automatically cleaned up by GC.

                  Equations
                  Instances For

                    Create texture view. Automatically cleaned up by GC.

                    Equations
                    Instances For

                      Create command encoder. Automatically cleaned up by GC.

                      Equations
                      Instances For

                        Begin render pass. Automatically cleaned up by GC.

                        Equations
                        Instances For

                          Set pipeline in render pass

                          Equations
                          Instances For

                            Draw vertices in render pass

                            Equations
                            Instances For

                              Finish encoder and get command buffer. Automatically cleaned up by GC.

                              Equations
                              Instances For

                                Submit command buffer to GPU

                                Equations
                                Instances For

                                  Create shader module. Automatically cleaned up by GC.

                                  Equations
                                  Instances For

                                    Create render pipeline. Automatically cleaned up by GC.

                                    Equations
                                    Instances For
                                      def Hesper.GLFW.renderFrame (device : WebGPU.Device) (surface : Surface) (pipeline : RenderPipeline) :

                                      Render a single frame

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For