func drawShip(angle float32) { gl.PushMatrix() gl.Translatef(x, y, 0.0) gl.Rotatef(angle, 0.0, 0.0, 1.0) if thrust { gl.Color3f(1.0, 0.0, 0.0) gl.Begin(gl.LINE_STRIP) gl.Vertex2f(-0.75, -0.5) gl.Vertex2f(-1.75, 0) gl.Vertex2f(-0.75, 0.5) gl.End() } gl.Color3f(1.0, 1.0, 0.0) gl.Begin(gl.LINE_LOOP) gl.Vertex2f(2.0, 0.0) gl.Vertex2f(-1.0, -1.0) gl.Vertex2f(-0.5, 0.0) gl.Vertex2f(-1.0, 1.0) gl.Vertex2f(2.0, 0.0) gl.End() if shield { gl.Color3f(0.1, 0.1, 1.0) gl.Begin(gl.LINE_LOOP) for rad := 0.0; rad < 12.0; rad += 1.0 { gl.Vertex2f( float32(2.3*math.Cos(2*float64(rad)/math.Pi)+0.2), float32(2.0*math.Sin(2*float64(rad)/math.Pi))) } gl.End() } gl.PopMatrix() }
func display() { gl.Clear(gl.COLOR_BUFFER_BIT) bitmap_output(40, 35, "This is written in a GLUT bitmap font.", glut.BITMAP_TIMES_ROMAN_24) bitmap_output(30, 210, "More bitmap text is a fixed 9 by 15 font.", glut.BITMAP_9_BY_15) bitmap_output(70, 240, " Helvetica is yet another bitmap font.", glut.BITMAP_HELVETICA_18) gl.MatrixMode(gl.PROJECTION) gl.PushMatrix() gl.LoadIdentity() glu.Perspective(40.0, 1.0, 0.1, 20.0) gl.MatrixMode(gl.MODELVIEW) gl.PushMatrix() glu.LookAt(0.0, 0.0, 4.0, /* eye is at (0,0,30) */ 0.0, 0.0, 0.0, /* center is at (0,0,0) */ 0.0, 1.0, 0.0) /* up is in postivie Y direction */ gl.PushMatrix() gl.Translatef(0, 0, -4) gl.Rotatef(50, 0, 1, 0) stroke_output(-2.5, 1.1, " This is written in a", glut.STROKE_ROMAN) stroke_output(-2.5, 0, " GLUT stroke font.", glut.STROKE_ROMAN) stroke_output(-2.5, -1.1, "using 3D perspective.", glut.STROKE_ROMAN) gl.PopMatrix() gl.MatrixMode(gl.MODELVIEW) gl.PopMatrix() gl.MatrixMode(gl.PROJECTION) gl.PopMatrix() gl.MatrixMode(gl.MODELVIEW) gl.Flush() }
func reshape(w, h int) { gl.Viewport(0, 0, w, h) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(0, float64(w), 0, float64(h), -1, 1) gl.Scalef(1, -1, 1) gl.Translatef(0, float32(-h), 0) gl.MatrixMode(gl.MODELVIEW) }
func stroke_output(x, y float32, str string, font glut.StrokeFont) { gl.PushMatrix() gl.Translatef(x, y, 0) gl.Scalef(0.005, 0.005, 0.005) for _, ch := range str { font.Character(ch) } gl.PopMatrix() }
func reshape(w, h int) { /* Because Gil specified "screen coordinates" (presumably with an upper-left origin), this short bit of code sets up the coordinate system to correspond to actual window coodrinates. This code wouldn't be required if you chose a (more typical in 3D) abstract coordinate system. */ gl.Viewport(0, 0, w, h) /* Establish viewing area to cover entire window. */ gl.MatrixMode(gl.PROJECTION) /* Start modifying the projection matrix. */ gl.LoadIdentity() /* Reset project matrix. */ gl.Ortho(0, float64(w), 0, float64(h), -1, 1) /* Map abstract coords directly to window coords. */ gl.Scalef(1, -1, 1) /* Invert Y axis so increasing Y goes down. */ gl.Translatef(0, float32(-h), 0) /* Shift origin up to upper-left corner. */ }