gfx

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package gfx boots a 2D window on the GoGPU stack.

Layout:

gogpu  — window, input, lifecycle
gg     — 2D drawing (via ggcanvas → surface)
wgpu   — pulled in transitively (GPU API)

g3d is intentionally not wired here; add it when a 3D game needs it.

Build with CGO disabled (Pure Go backend):

CGO_ENABLED=0 go run ./examples/hello2d

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

App is a thin gogpu + ggcanvas host for 2D games and tools.

func New

func New(cfg Config) *App

New creates an App. Call OnDraw, then Run.

func (*App) EventSource

func (a *App) EventSource() gpucontext.EventSource

EventSource returns the gogpu event source (keys, pointer, …).

func (*App) Native

func (a *App) Native() *gogpu.App

Native returns the underlying gogpu.App for advanced use (input polling, animation tokens, multi-window, etc.).

func (*App) OnDraw

func (a *App) OnDraw(fn DrawFunc) *App

OnDraw sets the per-frame 2D draw callback.

func (*App) RequestRedraw

func (a *App) RequestRedraw()

RequestRedraw schedules another frame when Continuous is false.

func (*App) Run

func (a *App) Run() error

Run opens the window and blocks until it closes.

type Config

type Config struct {
	Title  string
	Width  int
	Height int
	// Continuous keeps redrawing every frame (game loops).
	// When false, redraw only on RequestRedraw / input (power-friendly).
	Continuous bool
}

Config configures the window. Zero values get sensible defaults.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a 1280×720 continuous game window titled "Gomag".

type DrawFunc

type DrawFunc func(dc *gg.Context, width, height int)

DrawFunc is called each frame with a gg drawing context and logical size.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL