Skip to content

Commit 7aa48a1

Browse files
committed
Tue Jan 28 07:56:33 PM CET 2025
1 parent 3b8c5be commit 7aa48a1

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Getting started with SDL2 and Go on Wayland.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,31 @@ The output looks like the following
5454
```
5555
2025/01/26 12:40:32 INFO Initializing...
5656
```
57+
58+
# Press Q to exit
59+
60+
Replace `time.Sleep` with the following, will exit when `q` is pressed or the program gets a quit signal from the system
61+
```go
62+
for {
63+
switch e := sdl.PollEvent().(type) {
64+
case *sdl.QuitEvent:
65+
os.Exit(0)
66+
case *sdl.KeyboardEvent:
67+
if e.Keysym.Sym == sdl.K_q {
68+
os.Exit(0)
69+
}
70+
}
71+
}
72+
```
73+
74+
# Load an Image
75+
76+
Before updating the surface we can load an image and draw it
77+
78+
```go
79+
i, err := sdl.LoadBMP("image.bmp")
80+
ErrAndExit("Failed to load image", err)
81+
defer i.Free()
82+
83+
ErrAndExit("Failed to draw image", i.Blit(nil, s, &sdl.Rect{X: 0, Y: 0}))
84+
```

0 commit comments

Comments
 (0)