Advertisement
cjburkey01

First Go Program with OpenGL (3.3)

Oct 21st, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.27 KB | None | 0 0
  1. package main
  2.  
  3. import ("fmt"
  4.         "runtime"
  5.         "github.com/go-gl/glfw/v3.2/glfw"
  6.         "github.com/go-gl/gl/v3.3-core/gl")
  7.  
  8. const  (windowWidth = 960
  9.         windowHeight = 540)
  10.  
  11. func main() {
  12.     fmt.Printf("launching\n")
  13.    
  14.     runtime.LockOSThread()
  15.    
  16.     if err := glfw.Init(); err != nil {
  17.         panic(fmt.Errorf("could not initialize glfw: %v", err))
  18.     }
  19.    
  20.     fmt.Printf("glfw initialized\n")
  21.    
  22.     glfw.WindowHint(glfw.ContextVersionMajor, 3)
  23.     glfw.WindowHint(glfw.ContextVersionMinor, 3)
  24.     glfw.WindowHint(glfw.Resizable, glfw.True)
  25.     glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
  26.     glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
  27.    
  28.     fmt.Printf("glfw hints defined\n")
  29.    
  30.     win, err := glfw.CreateWindow(windowWidth, windowHeight, "Hello World!", nil, nil)
  31.    
  32.     if err != nil {
  33.         panic(fmt.Errorf("could not create glfw window: %v", err))
  34.     }
  35.    
  36.     fmt.Printf("glfw window created\n")
  37.    
  38.     win.MakeContextCurrent()
  39.    
  40.     if err := gl.Init(); err != nil {
  41.         panic(fmt.Errorf("opengl init error: %v", err))
  42.     }
  43.    
  44.     fmt.Printf("opengl context created\n")
  45.    
  46.     gl.ClearColor(0.0, 0.5, 1.0, 1.0)
  47.    
  48.     fmt.Printf("launched\n")
  49.    
  50.     for !win.ShouldClose() {
  51.         gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
  52.         win.SwapBuffers()
  53.         glfw.PollEvents()
  54.     }
  55.    
  56.     fmt.Printf("closing\n")
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement