Stuntkoala

Go SDL Example

Dec 11th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.93 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "os"
  6.     "time"
  7.     "github.com/veandco/go-sdl2/sdl"
  8. )
  9.  
  10. func main() {
  11.     /* Initialize SDL. */
  12.     err := sdl.Init(sdl.INIT_EVERYTHING)
  13.     if err != nil {
  14.         fmt.Fprintf(os.Stderr, "could not initialize SDL: %v", err)
  15.     }
  16.  
  17.     // Create the window where we will draw.
  18.     w, r, err := sdl.CreateWindowAndRenderer(900, 600, sdl.WINDOW_SHOWN)
  19.     _, _ = w, r
  20.  
  21.     // Select the color for drawing.
  22.     r.SetDrawColor(128, 128, 128, 255)
  23.  
  24.     // Clear the entire screen to our selected color.
  25.     r.Clear()
  26.  
  27.     // Draw single Pixel
  28.     r.SetDrawColor(255, 0, 0, 255)
  29.     r.DrawPoint(12, 12)
  30.  
  31.     /* Up until now everything was drawn behind the scenes.
  32.        This will show the new, red contents of the window.*/
  33.     r.Present()
  34.  
  35.     // Keep Window open 5 seconds
  36.     time.Sleep(5 * time.Second)
  37.  
  38.     // Quit properly
  39.     defer sdl.Quit()
  40.     defer w.Destroy()
  41. }
Advertisement
Add Comment
Please, Sign In to add comment