window

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Window

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

Window wraps gogpu App on auto mode (GraphicsAPIAuto, RenderModeAuto). It owns the OS surface and app lifecycle. All drawing goes through the render package — Window does not draw.

func NewWindow

func NewWindow(cfg WindowConfig) (*Window, error)

func (*Window) App

func (w *Window) App() *gogpu.App

func (*Window) Close

func (w *Window) Close()

func (*Window) DeviceProvider

func (w *Window) DeviceProvider() gogpu.DeviceProvider

DeviceProvider returns the GPU device provider for the render package.

func (*Window) OnResize

func (w *Window) OnResize(fn func(width, height int))

OnResize registers a callback for a change of size, in logical pixels. It fires when the window is resized and when it moves to a display with a different backing scale.

func (*Window) OnUpdate

func (w *Window) OnUpdate(fn func(dt float64))

OnUpdate registers the tick that runs whether or not a frame is drawn: input, simulation, anything that decides there is something new to show.

It matters on an OnDemand window. The loop blocks on OS events when idle, wakes on one, and calls this; OnDraw runs only if something asked for a frame. Polling input from the draw callback instead leaves an idle window deaf, because no frame means no polling and no polling means nothing ever asks for a frame.

GPU work belongs in the draw callback, not here.

func (*Window) RequestRedraw

func (w *Window) RequestRedraw()

RequestRedraw asks for one frame. It is what drives an OnDemand window, and it is harmless on a continuous one.

func (*Window) Run

func (w *Window) Run(onDraw func(dc *gogpu.Context)) error

Run starts the app draw loop. The callback receives the per-frame gogpu.Context and should call render.GPU methods to draw.

func (*Window) ScaleFactor

func (w *Window) ScaleFactor() float64

ScaleFactor is physical pixels per logical pixel, and it changes when the window moves between displays.

func (*Window) Size

func (w *Window) Size() (width, height int)

Size is the window in logical pixels, which is what a camera and a mouse position are in.

A game has to be able to ask: a window moved to a display with a different backing scale resizes its surface, and a projection built for the old size draws the scene into part of the new one. There was no way to ask before, so every example hard-coded the size it was created with.

type WindowConfig

type WindowConfig struct {
	Title     string
	W, H      int
	Resizable bool

	// OnDemand draws only when a redraw is asked for, rather than every
	// vsync. A game whose world is still then costs nothing: the frame that
	// would have been identical is never drawn and never presented, which is
	// where an idle window's GPU time goes.
	//
	// Wake something, move the camera, take an input - call RequestRedraw.
	OnDemand bool
}

Jump to

Keyboard shortcuts

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