EAGL.WindowBehaviour behaviour (eagl v0.5.0)
View SourceBehaviour for OpenGL window applications.
Defines callbacks for OpenGL window lifecycle management with automatic context setup and event handling.
Usage
defmodule MyApp do
use EAGL.Window
@impl true
def setup do
# Initialize shaders, load models, etc.
{:ok, initial_state}
end
@impl true
def render(width, height, state) do
# Clear and render your scene
:gl.clearColor(0.2, 0.3, 0.3, 1.0)
:gl.clear(@gl_color_buffer_bit)
# ... render content
:ok
end
@impl true
def cleanup(state) do
# Clean up resources
:ok
end
end
# Run the application
EAGL.Window.run(MyApp, "My OpenGL App")
Summary
Callbacks
Called when the window is being closed. Should clean up resources in state.
Called when an event occurs (keyboard, mouse, etc.). This callback is optional. If not implemented, events are ignored. Should return {:ok, new_state} to continue with updated state.
Called when the window needs to be rendered. The OpenGL context is already current and the viewport is set.
Called when the OpenGL context is ready and shaders should be created. Should return {:ok, state} or {:error, reason}
Callbacks
@callback cleanup(any()) :: :ok
Called when the window is being closed. Should clean up resources in state.
Called when an event occurs (keyboard, mouse, etc.). This callback is optional. If not implemented, events are ignored. Should return {:ok, new_state} to continue with updated state.
Called when the window needs to be rendered. The OpenGL context is already current and the viewport is set.
Called when the OpenGL context is ready and shaders should be created. Should return {:ok, state} or {:error, reason}