示例#1
0
// DrawArrays implements the opengl.OpenGl interface.
func (native *OpenGl) DrawArrays(mode uint32, first int32, count int32) {
	gl.DrawArrays(mode, first, count)
}
示例#2
0
func windowLoop(window *sdl.Window, cameraMatrixUniform int32) {
	var (
		yrot       float32
		xrot       float32
		buttonDown bool
	)

	numFrame := 0
	count := 0
	t := time.Now()

	for {
		c := time.Now()
		dt := c.Sub(t)
		t = c

		if numFrame > count {
			fmt.Println("\rDeltaTime:", dt)
			count += 5
		}
		numFrame++

		for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
			switch t := event.(type) {
			case *sdl.QuitEvent:
				return
			case *sdl.KeyDownEvent:
				if t.Keysym.Sym == sdl.K_ESCAPE {
					return
				}
			case *sdl.MouseButtonEvent:
				if t.State == 1 {
					buttonDown = true
				} else {
					buttonDown = false
				}
			case *sdl.MouseMotionEvent:
				if buttonDown {
					xrot += float32(t.YRel) * 0.001
					yrot += float32(t.XRel) * 0.001
				}
			}
		}

		gl.Clear(gl.COLOR_BUFFER_BIT)

		xq := mgl32.QuatRotate(xrot, mgl32.Vec3{1, 0, 0})
		yq := mgl32.QuatRotate(yrot, mgl32.Vec3{0, 1, 0})

		mat := xq.Mul(yq).Mat4()
		//mat = mat.Mul4(mgl32.Translate3D(0,0,-0.5))

		gl.UniformMatrix4fv(cameraMatrixUniform, 1, false, &mat[0])

		gl.DrawArrays(gl.TRIANGLES, 0, 6)

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