Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a86fadc
feat: added implemantation for wasm
CWBudde Apr 12, 2025
4c137ef
feat: improved: README.md and added index.html
CWBudde Apr 12, 2025
c87595a
fix: slightly advanced readme
CWBudde Apr 13, 2025
4c41cde
fix: delayed audio playback
CWBudde May 2, 2025
8ee1398
fix: delayed audio playback
CWBudde May 2, 2025
dbedfe0
fix: delayed audio playback
CWBudde May 2, 2025
09366f3
fix: fixed preloading and some clean-up
CWBudde May 4, 2025
4dd53e0
Support BlurImages and BlurText in GLFW
May 25, 2025
b6d1659
Refactor WASM code
May 30, 2025
602b31a
Add sample "everything" to test WASM port
Jun 7, 2025
a26efe4
WASM: draw pixelated lines
Jun 7, 2025
572c8ca
WASM: fix BlurImage
Jun 7, 2025
9e40d91
WASM: make right click not trigger context menu
Jun 8, 2025
28eb682
WASM: fix MouseWheelX and Y
Jun 8, 2025
9365d59
Windows: fix pixel issues when blurring images
Jun 8, 2025
8292c1f
WASM: fix DrawLine omitting end pixel
Jun 8, 2025
4742e34
WASM: Fix DrawRect being blurry
Jun 8, 2025
295785f
WASM: draw lines/rects/ellipses like desktop
Jun 8, 2025
8a501e1
WASM: handle keys like on desktop
Jun 8, 2025
2e14c8f
Refactor
Jun 8, 2025
cf154e8
WASM: handle mouse events like on desktop
Jun 8, 2025
d35b014
Add drawsm tool to manage WASM builds
Jun 9, 2025
fa88d7d
drawsm: use right wasm path for Go 1.23+
Jun 9, 2025
d018f5e
Remove debug output from everything sample
Jun 9, 2025
d647e16
WASM: fix preliminary text rendering
Jun 9, 2025
8b20cff
WASM: improve key repeat
Jun 10, 2025
c3f5755
Drawsm tool: separate serve and open, add show
Jun 14, 2025
5001726
WASM: load both images and sounds from embed.FS
Jun 21, 2025
1b31c7f
Remove BlurText, remove SDL2, use Go font
Jun 29, 2025
a977032
Do not send key repeats as key events
Jul 1, 2025
53450c8
WASM: fix fullscreen
Jul 1, 2025
b717df7
WASM: toggle fullscreen correctly
Jul 4, 2025
38acf7c
WASM: fix sound
Jul 5, 2025
bff19aa
Everything sample: play music from start
Jul 5, 2025
1ea12f6
Merge branch 'wasm'
Jul 5, 2025
ad36e82
WASM: go out of fullscreen on Close
Jul 5, 2025
e5e9146
Make Characters() not include control characters
Jul 5, 2025
08c808a
Add Window.SetIcon
Jul 9, 2025
7968d2c
Fix GetScaledTextSize being 1 pixel short
Jul 9, 2025
1ecb9b9
Add some letters to desktop fonts
Jul 9, 2025
45ca70a
Return ErrImageLoading on WASM
Jul 29, 2025
44daf7a
drawsm tool: pass build args to drawsm run/build
Aug 1, 2025
3392b69
Only set the icon once
Aug 2, 2025
4907232
Show mouse cursor after game is over
Aug 5, 2025
f095dc6
WASM: fix negative width/height image draw
Aug 5, 2025
08bd1fc
feat: added new x11 backend based on agg_go
CWBudde Mar 9, 2026
6928cfb
fix: absolute library use
CWBudde Mar 9, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 48 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,66 @@
prototype
=========
# prototype

Simply prototype 2D games using an easy, minimal interface that lets you draw simple primitives and images on the screen, easily handle mouse and keyboard events and play sounds.
Simply prototype 2D games using an easy, minimal interface that lets you draw
simple primitives and images on the screen, easily handle mouse and keyboard
events, and play sounds.

![Games](https://github.com/gonutz/prototype/blob/master/samples/screenshots/games.png)

Installation
------------
## Installation

Install the [Go programming language](https://golang.org/dl/). After clicking the download link you will be referred to the installation instructions for your specific operating system.
Install the [Go programming language](https://golang.org/dl/). After clicking
the download link you will be referred to the installation instructions for your
specific operating system.

Install [Git](https://git-scm.com/downloads) and make it available in the PATH so the go tool can use it.
Install [Git](https://git-scm.com/downloads) and make it available in the PATH
so the Go tool can use it.

For Linux and OS X you need a C compiler installed. On Windows this is not necessary.
For Linux and macOS, you need a C compiler installed. On Windows this is not
necessary.

On Linux there are two backends available, GLFW and SDL2. For GLFW you need these libraries installed (tested on Linux Mint, other distros might be slightly different):
### Supported Targets

`libx11-dev libxrandr-dev libgl1-mesa-dev libxcursor-dev libxinerama-dev libxi-dev`
The prototype framework supports multiple targets:

GLFW is used by default. To use SDL2 you need to add `-tags sdl2` to your Go builds, e.g. `go run -tags sdl2 main.go`. Also you need the SDL2 libraries installed:
#### Windows (default)

`libsdl2-dev libsdl2-mixer-dev libsdl2-image-dev`
- Uses Direct3D 9
- No additional dependencies needed

#### Linux/macOS (GLFW backend)

Install the library and samples by running the following on your command line:
- Uses OpenGL via GLFW
- Install required packages (example for Ubuntu/Debian):
```sh
sudo apt install libx11-dev libxrandr-dev libgl1-mesa-dev libxcursor-dev libxinerama-dev libxi-dev
```

go get github.com/gonutz/prototype/...
#### WebAssembly (experimental)

Documentation
-------------
To build and run a WASM version of your game, you can use the `drawsm` tool.
Install it with

For a description of all library functions, see [the godoc page](http://godoc.org/github.com/gonutz/prototype/draw) for this project. Note that most of the functionality is in the Window interface and hence the descriptions are listed as code comments in the source for that type.
go install github.com/gonutz/prototype/cmd/drawsm@latest

Example
-------
It allows you to run your game locally from within your project directory with

```Go
drawsm run

or build it into the project directory with

drawsm build

## Installation (Library & Samples)

## Documentation

For a description of all library functions, see [the package doc
page](https://pkg.go.dev/github.com/gonutz/prototype/draw). Most functionality
is in the `Window` interface, and documented via code comments.

## Example

```go
package main

import (
Expand All @@ -49,11 +74,9 @@ func main() {
}

func update(window draw.Window) {
// find the screen center
w, h := window.Size()
centerX, centerY := w/2, h/2

// draw a button in the center of the screen
mouseX, mouseY := window.MousePosition()
mouseInCircle := math.Hypot(float64(mouseX-centerX), float64(mouseY-centerY)) < 20
color := draw.DarkRed
Expand All @@ -66,16 +89,13 @@ func update(window draw.Window) {
window.DrawScaledText("Close!", centerX-40, centerY+25, 1.6, draw.Green)
}

// check all mouse clicks that happened during this frame
for _, click := range window.Clicks() {
dx, dy := click.X-centerX, click.Y-centerY
squareDist := dx*dx + dy*dy
if squareDist <= 20*20 {
// close the window and end the application
if dx*dx+dy*dy <= 20*20 {
window.Close()
}
}
}
```
This example displays a window with a round button in the middle to close it. It demonstrates some basic drawing and event handling code.

This example displays a window with a round button in the middle to close it. It demonstrates basic drawing and event handling.
Binary file added blocks
Binary file not shown.
19 changes: 19 additions & 0 deletions cmd/drawsm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# drawsm

This tool helps manage WASM builds of your games.

Install it with `go install github.com/gonutz/prototype/cmd/drawsm@latest`.

To run your game locally as a WASM build, call `drawsm run` from your project
directory. This will build the game and serve it locally on port 8080. It will
open the default browser at the local URL.

To build your game use `drawsm build`. This will generate a template
`index.html` and copy your Go installation's `wasm_exec.js` to the project
directory. These files, along with the compilation output `main.wasm` are
necessary to server your game in the browser.

To serve the built files use `drawsm serve`. This serves the game locally on
port 8080 and opens the default browser at this location.

Call `drawsm help` for the tool's help text.
Loading