func initOpenGl(window *glfw.Window, w, h int) { w, h = window.GetSize() // query window to get screen pixels width, height := window.GetFramebufferSize() gl.Viewport(0, 0, width, height) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(0, float64(w), 0, float64(h), -1, 1) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.ClearColor(.25, .88, .83, 1) // turquoise }
// renders the display on each update func render() { gl.Clear(gl.COLOR_BUFFER_BIT) gl.Enable(gl.BLEND) gl.Enable(gl.POINT_SMOOTH) gl.Enable(gl.LINE_SMOOTH) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.LoadIdentity() // draw pipes for _, pipeBox := range pipe { gl.PushMatrix() pos := pipeBox.Body.Position() gl.Translatef(float32(pos.X), float32(pos.Y), 0.0) drawSquare(.19, .8, .19, 1) // limegreen gl.PopMatrix() } // draw flappy for _, flappyBird := range flappyBirds { gl.PushMatrix() pos := flappyBird.Body.Position() gl.Translatef(float32(pos.X), float32(pos.Y), 0.0) drawSquare(1, .84, 0, 1) // gold gl.PopMatrix() } gl.Color4f(1, 0, 1, 1) scoreStr := "[ Score: " + strconv.Itoa(score) + " ]" // draw score drawScore(scoreStr) }