func init_() { pos := []float32{5.0, 5.0, 10.0, 0.0} red := []float32{0.8, 0.1, 0.0, 1.0} green := []float32{0.0, 0.8, 0.2, 1.0} blue := []float32{0.2, 0.2, 1.0, 1.0} gl.Lightfv(gl.LIGHT0, gl.POSITION, pos) gl.Enable(gl.CULL_FACE) gl.Enable(gl.LIGHTING) gl.Enable(gl.LIGHT0) gl.Enable(gl.DEPTH_TEST) /* make the gears */ gear1 = gl.GenLists(1) gl.NewList(gear1, gl.COMPILE) gl.Materialfv(gl.FRONT, gl.AMBIENT_AND_DIFFUSE, red) gear(1.0, 4.0, 1.0, 20, 0.7) gl.EndList() gear2 = gl.GenLists(1) gl.NewList(gear2, gl.COMPILE) gl.Materialfv(gl.FRONT, gl.AMBIENT_AND_DIFFUSE, green) gear(0.5, 2.0, 2.0, 10, 0.7) gl.EndList() gear3 = gl.GenLists(1) gl.NewList(gear3, gl.COMPILE) gl.Materialfv(gl.FRONT, gl.AMBIENT_AND_DIFFUSE, blue) gear(1.3, 2.0, 0.5, 10, 0.7) gl.EndList() gl.Enable(gl.NORMALIZE) if *printInfo { print("GL_RENDERER = ", gl.GetString(gl.RENDERER), "\n") print("GL_VERSION = ", gl.GetString(gl.VERSION), "\n") print("GL_VENDOR = ", gl.GetString(gl.VENDOR), "\n") print("GL_EXTENSIONS = ", gl.GetString(gl.EXTENSIONS), "\n") } }
func cube(color []float32) { gl.Materialfv(gl.FRONT, gl.AMBIENT_AND_DIFFUSE, whiteColor) gl.Color4f(color[0], color[1], color[2], color[3]) // TOP gl.Begin(gl.TRIANGLE_FAN) gl.Vertex3f(cubeWidth, cubeWidth, -cubeWidth) gl.Vertex3f(-cubeWidth, cubeWidth, -cubeWidth) gl.Vertex3f(-cubeWidth, cubeWidth, cubeWidth) gl.Vertex3f(cubeWidth, cubeWidth, cubeWidth) gl.End() // Bottom gl.Begin(gl.TRIANGLE_FAN) gl.Vertex3f(cubeWidth, -cubeWidth, cubeWidth) gl.Vertex3f(-cubeWidth, -cubeWidth, cubeWidth) gl.Vertex3f(-cubeWidth, -cubeWidth, -cubeWidth) gl.Vertex3f(cubeWidth, -cubeWidth, -cubeWidth) gl.End() // Front gl.Begin(gl.TRIANGLE_FAN) gl.Vertex3f(cubeWidth, cubeWidth, cubeWidth) gl.Vertex3f(-cubeWidth, cubeWidth, cubeWidth) gl.Vertex3f(-cubeWidth, -cubeWidth, cubeWidth) gl.Vertex3f(cubeWidth, -cubeWidth, cubeWidth) gl.End() // Back gl.Begin(gl.TRIANGLE_FAN) gl.Vertex3f(cubeWidth, -cubeWidth, -cubeWidth) gl.Vertex3f(-cubeWidth, -cubeWidth, -cubeWidth) gl.Vertex3f(-cubeWidth, cubeWidth, -cubeWidth) gl.Vertex3f(cubeWidth, cubeWidth, -cubeWidth) gl.End() // Left gl.Begin(gl.TRIANGLE_FAN) gl.Vertex3f(-cubeWidth, cubeWidth, cubeWidth) gl.Vertex3f(-cubeWidth, cubeWidth, -cubeWidth) gl.Vertex3f(-cubeWidth, -cubeWidth, -cubeWidth) gl.Vertex3f(-cubeWidth, -cubeWidth, cubeWidth) gl.End() // Right gl.Begin(gl.TRIANGLE_FAN) gl.Vertex3f(cubeWidth, cubeWidth, -cubeWidth) gl.Vertex3f(cubeWidth, cubeWidth, cubeWidth) gl.Vertex3f(cubeWidth, -cubeWidth, cubeWidth) gl.Vertex3f(cubeWidth, -cubeWidth, -cubeWidth) gl.End() //* gl.Color4f(color[0]/1.2, color[1]/1.2, color[2]/1.2, 1.0) gl.Begin(gl.LINE_STRIP) // Start Drawing Our Player Using Lines // TOP gl.Vertex3f(cubeWidth, cubeWidth, -cubeWidth) gl.Vertex3f(-cubeWidth, cubeWidth, -cubeWidth) gl.Vertex3f(-cubeWidth, cubeWidth, cubeWidth) gl.Vertex3f(cubeWidth, cubeWidth, cubeWidth) // Front gl.Vertex3f(-cubeWidth, cubeWidth, cubeWidth) gl.Vertex3f(-cubeWidth, -cubeWidth, cubeWidth) gl.Vertex3f(cubeWidth, -cubeWidth, cubeWidth) // Bottom gl.Vertex3f(-cubeWidth, -cubeWidth, cubeWidth) gl.Vertex3f(-cubeWidth, -cubeWidth, -cubeWidth) gl.Vertex3f(cubeWidth, -cubeWidth, -cubeWidth) // Back gl.Vertex3f(-cubeWidth, -cubeWidth, -cubeWidth) gl.Vertex3f(-cubeWidth, cubeWidth, -cubeWidth) gl.Vertex3f(cubeWidth, cubeWidth, -cubeWidth) // Right gl.Vertex3f(cubeWidth, cubeWidth, cubeWidth) gl.Vertex3f(cubeWidth, -cubeWidth, cubeWidth) gl.Vertex3f(cubeWidth, -cubeWidth, -cubeWidth) // Left gl.Vertex3f(-cubeWidth, cubeWidth, cubeWidth) gl.Vertex3f(-cubeWidth, cubeWidth, -cubeWidth) gl.Vertex3f(-cubeWidth, -cubeWidth, -cubeWidth) gl.Vertex3f(-cubeWidth, -cubeWidth, cubeWidth) gl.End() //*/ }