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
Initialize GLFW with automatic cleanup
Equations
Instances For
Create a window. Automatically cleaned up by GC.
Equations
- Hesper.GLFW.createWindow width height title = Hesper.GLFW.Internal.createWindow width.toUInt32 height.toUInt32 title
Instances For
Check if window should close
Equations
Instances For
Poll for events
Instances For
Get key state
Equations
- Hesper.GLFW.getKey window key = do let state ← Hesper.GLFW.Internal.windowGetKey window key.toNat.toUInt32 pure (Hesper.GLFW.KeyAction.fromNat state.toNat)
Instances For
Create a surface. Automatically cleaned up by GC.
Equations
- Hesper.GLFW.createSurface device window = Hesper.GLFW.Internal.createSurface device window
Instances For
Configure surface dimensions and format
Equations
- Hesper.GLFW.configureSurface surface width height format = Hesper.GLFW.Internal.configureSurface surface width.toUInt32 height.toUInt32 format.toUInt32
Instances For
Get preferred surface format
Equations
- Hesper.GLFW.getSurfacePreferredFormat surface = do let format ← Hesper.GLFW.Internal.getSurfacePreferredFormat surface pure format.toNat
Instances For
Present surface
Equations
- Hesper.GLFW.present surface = Hesper.GLFW.Internal.surfacePresent surface
Instances For
Get current texture. Automatically cleaned up by GC.
Equations
- Hesper.GLFW.getCurrentTexture surface = Hesper.GLFW.Internal.getCurrentTexture surface
Instances For
Create texture view. Automatically cleaned up by GC.
Equations
- Hesper.GLFW.createTextureView texture = Hesper.GLFW.Internal.createTextureView texture
Instances For
Create command encoder. Automatically cleaned up by GC.
Equations
Instances For
Begin render pass. Automatically cleaned up by GC.
Equations
- Hesper.GLFW.beginRenderPass encoder view = Hesper.GLFW.Internal.beginRenderPass encoder view
Instances For
Set pipeline in render pass
Equations
- Hesper.GLFW.setPipeline pass pipeline = Hesper.GLFW.Internal.setRenderPipeline pass pipeline
Instances For
Draw vertices in render pass
Equations
- Hesper.GLFW.drawVertices pass count = Hesper.GLFW.Internal.draw pass count.toUInt32
Instances For
End render pass
Equations
Instances For
Finish encoder and get command buffer. Automatically cleaned up by GC.
Equations
- Hesper.GLFW.finishEncoder encoder = Hesper.GLFW.Internal.finishEncoder encoder
Instances For
Submit command buffer to GPU
Equations
- Hesper.GLFW.submit device cmd = Hesper.GLFW.Internal.submitCommand device cmd
Instances For
Create shader module. Automatically cleaned up by GC.
Equations
- Hesper.GLFW.createShaderModule device code = Hesper.GLFW.Internal.createShaderModule device code
Instances For
Create render pipeline. Automatically cleaned up by GC.
Equations
- Hesper.GLFW.createRenderPipeline device shader format = Hesper.GLFW.Internal.createRenderPipeline device shader format.toUInt32
Instances For
Render a single frame
Equations
- One or more equations did not get rendered due to their size.