Exemple #1
0
func main() {
	globalState.Mouse = make(map[int]bool)
	flag.Parse()
	var err error
	if err = glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	if len(flag.Args()) == 0 {
		old := flag.Usage
		flag.Usage = func() {
			old()
			fmt.Fprintf(os.Stderr, "You MUST pass the name of the file to view\n")
		}
		flag.Usage()
		return
	}

	mesh, err = wfobj.LoadMeshFromFile(flag.Args()[0])
	if err != nil {
		flag.Usage()
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.Terminate()

	if err = glfw.OpenWindow(Width, Height, 8, 8, 8, 8, 0, 8, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.CloseWindow()

	glfw.SetSwapInterval(1)
	glfw.SetWindowTitle(Title)
	glfw.SetWindowSizeCallback(onResize)
	glfw.SetKeyCallback(onKey)
	glfw.SetCharCallback(onChar)
	glfw.SetMouseWheelCallback(onWheel)
	glfw.SetMouseButtonCallback(onMouseButton)
	glfw.SetMousePosCallback(onMousePos)

	initGL()

	running = true
	for running && glfw.WindowParam(glfw.Opened) == 1 {
		handleInput()
		drawScene()
	}
}
Exemple #2
0
func (o *OpenGl) Init() {
	if err := glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "glfw: %s\n", err)
		return
	}
	defer glfw.Terminate()

	if err := glfw.OpenWindow(o.width, o.height, 0, 0, 0, 0, 16, 0, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "glfw: %s\n", err)
		return
	}
	defer glfw.CloseWindow()

	glfw.SetSwapInterval(1)
	glfw.SetWindowTitle(o.title)

	if err := gl.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "gl: %s\n", err)
	}

	glfw.SetKeyCallback(glfw.KeyHandler(o.keyboard))
	glfw.SetMouseButtonCallback(glfw.MouseButtonHandler(o.mouseClick))
	glfw.SetMousePosCallback(glfw.MousePosHandler(o.mouseMove))
	glfw.SetMouseWheelCallback(glfw.MouseWheelHandler(o.mouseWheel))

	if err := o.initScene(); err != nil {
		fmt.Fprintf(os.Stderr, "init: %s\n", err)
		return
	}

	for glfw.WindowParam(glfw.Opened) == 1 {
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

		if o.display3d != nil {
			o.set3dView()
			o.display3d()
		}
		if o.display2d != nil {
			o.set2dView()
			o.display2d()
		}

		glfw.SwapBuffers()
		time.Sleep(20 * time.Millisecond)
		//<-o.redisplay
	}
}
Exemple #3
0
// Sets up input handlers
func InitInputHandlers() {
	InitKeyHandlers()

	glfw.SetMousePosCallback(func(x, y int) {

		dx, dy := x-mousePrevX, y-mousePrevY
		mousePrevX, mousePrevY = x, y
		if mouseButton[0] == 0 {
			return
		}

		Rot[0] += int(deltaLook * float64(dx))
		Rot[1] += int(deltaLook * float64(dy))

		// limit viewing angles
		for i := range Rot {
			if Rot[i] > 360 {
				Rot[i] = 0
			}
			if Rot[i] < 0 {
				Rot[i] += 360
			}
		}
		log.Println("rot:", Rot)
	})

	glfw.SetMouseButtonCallback(func(button, state int) {
		//log.Println("mousebutton:", button, state)
		mouseButton[button] = state
	})

	glfw.SetMouseWheelCallback(func(delta int) {
		//log.Println("mousewheel:", delta)
		glfw.SetMouseWheel(0)
	})

	glfw.SetWindowSizeCallback(func(w, h int) {
		Width, Height = w, h
		InitViewport()
	})
}
Exemple #4
0
func setupWindow(width int, height int, fullscreen bool) bool {
	// Create OpenGL window
	var windowType int
	if fullScreen {
		windowType = glfw.Fullscreen
	} else {
		windowType = glfw.Windowed
	}

	if err := glfw.OpenWindow(width, height, 8, 8, 8, 8, 24, 8, windowType); err != nil {
		glfw.Terminate()
		return false
	}

	// Disable vertical synchronization
	glfw.SetSwapInterval(0)

	// Set listeners
	glfw.SetWindowCloseCallback(windowCloseListener)
	glfw.SetKeyCallback(keyPressListener)
	glfw.SetMousePosCallback(mouseMoveListener)

	return true
}
Exemple #5
0
Fichier : input.go Projet : vron/fm
func initInput() {
	// Start listening to mouse events
	glfw.SetMouseButtonCallback(click)
	glfw.SetMousePosCallback(move)
}
Exemple #6
0
func initInput() {
	glfw.SetKeyCallback(onKey)
	glfw.SetMouseButtonCallback(onMouseBttn)
	glfw.SetMousePosCallback(onMousePos)
}
Exemple #7
0
func Init() {
	glfw.SetMouseWheelCallback(mouseWheelHandler)
	glfw.SetMouseButtonCallback(mouseButtonHandler)
	glfw.SetMousePosCallback(mousePosHandler)
	glfw.SetKeyCallback(keyHandler)
}