Skip to content

Instantly share code, notes, and snippets.

@BrentFarris
Last active June 18, 2023 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrentFarris/78f6a1ad1fc713821cc75601cb47bfe1 to your computer and use it in GitHub Desktop.
Save BrentFarris/78f6a1ad1fc713821cc75601cb47bfe1 to your computer and use it in GitHub Desktop.
Getting Go setup with SDL for game development video - https://youtu.be/yxK_dwJ3Bbc
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}",
"buildFlags": "-tags=DESKTOP",
}
]
}
package main
import (
"fmt"
sdl "github.com/veandco/go-sdl2/sdl"
)
func main() {
if err := sdl.Init(sdl.INIT_EVERYTHING); err != nil {
panic("Failed to initialize a window")
}
win, err := sdl.CreateWindow("GO SDL Window",
sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
1280, 720, sdl.WINDOW_SHOWN|sdl.WINDOW_RESIZABLE)
if err != nil {
panic("Failed to create the SDL window")
}
quit := false
for !quit {
for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
if e.GetType() == sdl.QUIT {
quit = true
}
switch e := e.(type) {
case *sdl.KeyboardEvent:
fmt.Printf("%d", e.Keysym)
}
}
}
win.Destroy()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment