Example #1
0
func setupGL() {
	gl.ShadeModel(gl.FLAT)
	gl.ClearColor(0.75, 0.75, 0.75, 1.0)

	gl.Enable(gl.DEPTH_TEST)
	gl.LineWidth(1)

	gl.Viewport(0, 0, winWidth, winHeight)
	gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)
	gluPerspective(45, float64(winWidth)/winHeight, 10, 1000)

	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
Example #2
0
func windowLoop(window *sdl.Window) {
	data := &renderData{}

	data.renderSections = true
	data.zoom = -250
	data.nodes = loadTree("cmd/packer/test.priv.oct")
	data.box = genBox()
	defer gl.DeleteLists(data.box, 1)

	buttonDown := false
	t := float64(sdl.GetTicks())
	for {
		ticks := float64(sdl.GetTicks()) * 0.001
		dt := ticks - t
		t = ticks

		for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
			switch t := event.(type) {
			case *sdl.QuitEvent:
				return
			case *sdl.KeyDownEvent:
				switch t.Keysym.Sym {
				case sdl.K_ESCAPE:
					return
				case sdl.K_SPACE:
					data.renderSections = !data.renderSections
				case sdl.K_PLUS:
					data.minNodeSize += 1.0
				case sdl.K_MINUS:
					data.minNodeSize -= 1.0
				}
			case *sdl.MouseButtonEvent:
				if t.State == 1 {
					buttonDown = true
				} else {
					buttonDown = false
				}
			case *sdl.MouseMotionEvent:
				if buttonDown {
					data.xrot += dt * float64(t.YRel) * rotSpeed
					data.yrot += dt * float64(t.XRel) * rotSpeed
				}
			case *sdl.MouseWheelEvent:
				data.zoom += dt * float64(t.Y) * rotSpeed
			}
		}

		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

		renderTree(data, &data.nodes[0], point3d{0, 0, 0}, 100)

		gl.Disable(gl.DEPTH_TEST)
		drawAxis(data)
		gl.Enable(gl.DEPTH_TEST)

		sdl.GL_SwapWindow(window)

		if glErr := gl.GetError(); glErr != gl.NO_ERROR {
			panic(fmt.Errorf("GL error: %x", glErr))
		}
	}
}