Graphics, GUI and Games

36.1 gg (2D Graphics on Top of sokol)

gg supports shapes, images (create_image), text, input events, and runs on desktop, mobile (vab for Android), and the web (emscripten).

sokol for low-level graphics (sokol_gfx), plus custom shaders (v shader).

import gg
import gx

struct App {
mut:
	gg &gg.Context = unsafe { nil }
	x  f32 = 100
}

fn frame(mut app App) {
	app.gg.begin()
	app.gg.draw_rect_filled(app.x, 100, 50, 50, gx.blue)
	app.gg.draw_text(10, 10, 'Hello gg!', gx.TextCfg{color: gx.black, size: 20})
	app.gg.end()
	app.x += 1
}

fn on_event(e &gg.Event, mut app App) {
	if e.typ == .key_down && e.key_code == .escape { app.gg.quit() }
}

fn main() {
	mut app := &App{}
	app.gg = gg.new_context(
		width: 800
		height: 600
		window_title: 'gg demo'
		bg_color: gx.white
		frame_fn: frame
		event_fn: on_event
		user_data: app
	)
	app.gg.run()
}

36.2 GUI

V UI (v install ui): cross-platform declarative widgets (buttons, textboxes, lists, canvas, layouts), built on gg.

Alternatives: webview bindings (HTML UI), iui (immediate-mode), term.ui for terminal UIs.

36.3 Games

Examples in v/examples: tetris, 2048, flappy bird, snake, asteroids, game of life, fireworks, sokol 3D cubes. Run them with v run examples/tetris.

3D: sokol + custom shaders, raylib bindings (vraylib via VPM).

Mobile builds with vab (Android APK/AAB).