// OpenGL draw function & timing func draw() { gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.PushMatrix() gl.Rotated(view_rotx, 1.0, 0.0, 0.0) gl.Rotated(view_roty, 0.0, 1.0, 0.0) gl.Rotated(view_rotz, 0.0, 0.0, 1.0) gl.PushMatrix() gl.Translated(-3.0, -2.0, 0.0) gl.Rotated(angle, 0.0, 0.0, 1.0) gl.CallList(gear1) gl.PopMatrix() gl.PushMatrix() gl.Translated(3.1, -2.0, 0.0) gl.Rotated(-2.0*angle-9.0, 0.0, 0.0, 1.0) gl.CallList(gear2) gl.PopMatrix() gl.PushMatrix() gl.Translated(-3.1, 4.2, 0.0) gl.Rotated(-2.0*angle-25.0, 0.0, 0.0, 1.0) gl.CallList(gear3) gl.PopMatrix() gl.PopMatrix() }
func PlaceObject(compiledPrim gl.List, scale [3]double, translation [3]double, rotation [4]double) { // objects are placed and transformed when necessary gl.PushMatrix() gl.Scaled(scale) gl.Translated(translation) gl.Rotated(rotation) gl.CallList(compiledPrim) gl.PopMatrix() }
func draw() { gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.PushMatrix() gl.Rotated(view_rotx, 1.0, 0.0, 0.0) gl.Rotated(view_roty, 0.0, 1.0, 0.0) gl.Rotated(view_rotz, 0.0, 0.0, 1.0) gl.PushMatrix() gl.Translated(-3.0, -2.0, 0.0) gl.Rotated(angle, 0.0, 0.0, 1.0) gl.CallList(gear1) gl.PopMatrix() gl.PushMatrix() gl.Translated(3.1, -2.0, 0.0) gl.Rotated(-2.0*angle-9.0, 0.0, 0.0, 1.0) gl.CallList(gear2) gl.PopMatrix() gl.PushMatrix() gl.Translated(-3.1, 4.2, 0.0) gl.Rotated(-2.0*angle-25.0, 0.0, 0.0, 1.0) gl.CallList(gear3) gl.PopMatrix() gl.PopMatrix() sdl.GL_SwapBuffers() Frames++ { t := sdl.GetTicks() if t-T0 >= 5000 { seconds := (t - T0) / 1000.0 fps := Frames / seconds print(Frames, " frames in ", seconds, " seconds = ", fps, " FPS\n") T0 = t Frames = 0 } } }