Esempio n. 1
0
// Hint sets implementation-specific modes.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glHint.xhtml
func Hint(target, mode Enum) {
	gl.Hint(uint32(target), uint32(mode))
}
Esempio n. 2
0
func (ctx *DrawContext) drawScreen(o *orrery.Orrery) {
	fullscreen := false

	gl.Viewport(0, 0, int32(ctx.width), int32(ctx.height))
	gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)

	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Translatef(0, 0, 0)

	t_delta := time.Duration(0)
	frametime := time.Second / 24
	log.Printf(`ft: %v`, frametime)

	frametimes := time.Duration(0)
	nsamples := 0
	slowest_frame := time.Duration(0)
	frames_over_deadline := 0

	defer func() {
		log.Printf(`average frame time: %v, #sample: %d`, frametimes/time.Duration(nsamples), nsamples)
		log.Printf(`slowest frame: %v, # of frames over %v: %d`, slowest_frame, frametime, frames_over_deadline)
	}()

	for {
		t_start := time.Now()

		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
		ctx.cam.Update()
		ctx.drawGrid()
		ctx.drawParticles(o)
		ctx.drawHud(o, t_delta)
		ctx.win.SwapBuffers()

		glfw.PollEvents()

		select {
		case cmd := <-ctx.cmd:
			switch cmd {
			case DRAW_QUIT:
				return
			case DRAW_FULLSCREEN:
				/*
					if fullscreen {
						ctx.win.SetFullscreen(0)
					} else {
						ctx.win.SetFullscreen(sdl.WINDOW_FULLSCREEN)
					}
				*/
				fullscreen = !fullscreen
			case DRAW_TOGGLE_WIREFRAME:
				ctx.wireframe = !ctx.wireframe
			case DRAW_TOGGLE_VERBOSE:
				ctx.verbose = !ctx.verbose
			}
		default:
			/* ignore */
		}

		t_delta = time.Since(t_start)
		frametimes += t_delta
		nsamples++
		if t_delta > slowest_frame {
			slowest_frame = t_delta
		}
		if t_delta > frametime {
			frames_over_deadline++
		}
		t_sleep := frametime.Nanoseconds() - t_delta.Nanoseconds()
		if t_sleep > 0 {
			time.Sleep(time.Duration(t_sleep) * time.Nanosecond)
		}
	}
}