func main() { // We need to lock the goroutine to one thread due time.Ticker runtime.LockOSThread() var err os.Error err = glfw.Init() if err != nil { fmt.Printf("GLFW: %s\n", err) return } defer glfw.Terminate() // You could probably change the required versions down glfw.OpenWindowHint(glfw.OpenGLVersionMajor, 3) glfw.OpenWindowHint(glfw.OpenGLVersionMinor, 3) glfw.OpenWindowHint(glfw.OpenGLProfile, 1) // Open Window with 8 bit Alpha err = glfw.OpenWindow(ScreenWidth, ScreenHeight, 0, 0, 0, 8, 0, 0, glfw.Windowed) if err != nil { fmt.Printf("GLFW: %s\n", err) return } defer glfw.CloseWindow() glfw.SetWindowTitle(WindowTitle) major, minor, rev := glfw.GLVersion() if major < 3 { fmt.Printf("Error your graphic card does not support OpenGL 3.3\n Your GL-Version is: %d, %d, %d\n", major, minor, rev) fmt.Println("You can try to lower the settings in glfw.OpenWindowHint(glfw.OpenGLVersionMajor/Minor.") } initStatus := gl.Init() // Init glew if initStatus != 0 { fmt.Printf("Error-code: %d Init-Status: %d\n", gl.GetError(), initStatus) } // Enable transparency in OpenGL gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) initResources() // We are limiting the calls to display() (frames per second) to 60. This prevents the 100% cpu usage. ticker := time.NewTicker(int64(second) / 60) // max 60 fps for { <-ticker.C move := float32(math.Sin(glfw.Time())) angle := float32(glfw.Time()) matrix = math3d.MakeTranslationMatrix(move, 0.0, 0.0) matrix = matrix.Multiply(math3d.MakeZRotationMatrix(angle)).Transposed() display() } // Free resources free() runtime.UnlockOSThread() }
func main() { var err os.Error err = glfw.Init() if err != nil { fmt.Printf("GLFW: %s\n", err) return } defer glfw.Terminate() glfw.OpenWindowHint(glfw.WindowNoResize, 1) glfw.OpenWindowHint(glfw.OpenGLDebugContext, 1) // You could probably change the required versions down glfw.OpenWindowHint(glfw.OpenGLVersionMajor, 3) glfw.OpenWindowHint(glfw.OpenGLVersionMinor, 3) glfw.OpenWindowHint(glfw.OpenGLProfile, 1) // Open Window with 8 bit Alpha err = glfw.OpenWindow(ScreenWidth, ScreenHeight, 0, 0, 0, 8, 0, 0, glfw.Windowed) if err != nil { fmt.Printf("GLFW: %s\n", err) return } defer glfw.CloseWindow() glfw.SetWindowTitle(WindowTitle) major, minor, rev := glfw.GLVersion() if major < 3 { fmt.Printf("Error your graphic card does not support OpenGL 3.3\n Your GL-Version is: %d, %d, %d\n", major, minor, rev) fmt.Println("You can try to lower the settings in glfw.OpenWindowHint(glfw.OpenGLVersionMajor/Minor.") } initStatus := gl.Init() // Init glew if initStatus != 0 { fmt.Printf("Error-code: %d Init-Status: %d\n", gl.GetError(), initStatus) } // Enable transparency in OpenGL gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) initResources() for { display() } // Free resources free() }
func (w *window) OpenGLVersion() (major, minor, rev int) { return glfw.GLVersion() }
func main() { // We need to lock the goroutine to one thread due time.Ticker runtime.LockOSThread() var err os.Error err = glfw.Init() if err != nil { fmt.Printf("GLFW: %s\n", err) return } defer glfw.Terminate() // You could probably change the required versions down glfw.OpenWindowHint(glfw.OpenGLVersionMajor, 3) glfw.OpenWindowHint(glfw.OpenGLVersionMinor, 3) glfw.OpenWindowHint(glfw.OpenGLProfile, 1) // Open Window with 8 bit Alpha err = glfw.OpenWindow(ScreenWidth, ScreenHeight, 0, 0, 0, 8, 8, 0, glfw.Windowed) if err != nil { fmt.Printf("GLFW: %s\n", err) return } defer glfw.CloseWindow() glfw.SetWindowTitle(WindowTitle) glfw.SetWindowSizeCallback(onResize) major, minor, rev := glfw.GLVersion() if major < 3 { fmt.Printf("Error your graphic card does not support OpenGL 3.3\n Your GL-Version is: %d, %d, %d\n", major, minor, rev) fmt.Println("You can try to lower the settings in glfw.OpenWindowHint(glfw.OpenGLVersionMajor/Minor.") } initStatus := gl.Init() // Init glew if initStatus != 0 { fmt.Printf("Error-code: %d Init-Status: %d\n", gl.GetError(), initStatus) } // Enable transparency in OpenGL gl.Enable(gl.BLEND) gl.Enable(gl.DEPTH_TEST) //gl.DepthFunc(gl.LESS) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) initResources() // We are limiting the calls to display() (frames per second) to 60. This prevents the 100% cpu usage. ticker := time.NewTicker(int64(second) / 60) // max 60 fps for { <-ticker.C angle := float32(glfw.Time()) anim := math3d.MakeYRotationMatrix(angle) model := math3d.MakeTranslationMatrix(0, 0, -4) view := math3d.MakeLookAtMatrix(math3d.Vector3{0, 2, 0}, math3d.Vector3{0, 0, -4}, math3d.Vector3{0, 1, 0}) projection := math3d.MakePerspectiveMatrix(45, float32(ScreenWidth)/float32(ScreenHeight), 0.1, 10.0) matrix = math3d.MakeIdentity().Multiply(projection).Multiply(view).Multiply(model).Multiply(anim) program.Use() uniformMTransform.UniformMatrix4fv(1, false, matrix.Transposed()) display() } // Free resources free() runtime.UnlockOSThread() }