Esempio n. 1
0
func Open(w, h int, sWin string, fullscreen bool) *Window {

	if GWindow != nil {
		panic("only one Window is allowed")
	}
	listener.GListener = listener.New()
	win := &Window{width: w, height: h, title: sWin, inputListener: listener.GListener}
	GWindow = win

	var err error
	if err = glfw.Init(); err != nil {
		panic(fmt.Sprintf("[e] %v\n", err))
	}
	mode := glfw.Windowed
	if fullscreen {
		mode = glfw.Fullscreen
	}
	if err = glfw.OpenWindow(win.width, win.height, 8, 8, 8, 0, 16, 0, mode); err != nil {
		panic(fmt.Sprintf("[e] %v\n", err))
	}
	gl.Init() //WHY?? (shader creation fails when not)

	glfw.SetSwapInterval(1)        // Enable vertical sync on cards that support it.
	glfw.SetWindowTitle(win.title) // Set window title
	//CALLBACKS
	glfw.SetWindowSizeCallback(func(w, h int) { GWindow.reshape(w, h) })
	glfw.SetWindowCloseCallback(listener.OnClose)
	glfw.SetMouseButtonCallback(listener.OnMouseButton)
	glfw.SetMouseWheelCallback(listener.OnMouseWheel)
	glfw.SetKeyCallback(listener.OnKey)
	glfw.SetCharCallback(listener.OnChar)

	win.initGL()
	return win
}
Esempio n. 2
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()
	}
}
Esempio n. 3
0
File: main.go Progetto: andrebq/glfw
func main() {
	var err error
	if err = glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	// Ensure glfw is cleanly terminated on exit.
	defer glfw.Terminate()

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

	// Ensure window is cleanly closed on exit.
	defer glfw.CloseWindow()

	// Enable vertical sync on cards that support it.
	glfw.SetSwapInterval(1)

	// Set window title
	glfw.SetWindowTitle("Simple GLFW window")

	// Hook some events to demonstrate use of callbacks.
	// These are not necessary if you don't need them.
	glfw.SetWindowSizeCallback(onResize)
	glfw.SetWindowCloseCallback(onClose)
	glfw.SetMouseButtonCallback(onMouseBtn)
	glfw.SetMouseWheelCallback(onMouseWheel)
	glfw.SetKeyCallback(onKey)
	glfw.SetCharCallback(onChar)

	// Start loop
	running := true
	for running {
		// OpenGL rendering goes here.

		// Swap front and back rendering buffers. This also implicitly calls
		// glfw.PollEvents(), so we have valid key/mouse/joystick states after
		// this. This behavior can be disabled by calling glfw.Disable with the
		// argument glfw.AutoPollEvents. You must be sure to manually call
		// PollEvents() or WaitEvents() in this case.
		glfw.SwapBuffers()

		// Break out of loop when Escape key is pressed, or window is closed.
		running = glfw.Key(glfw.KeyEsc) == 0 && glfw.WindowParam(glfw.Opened) == 1
	}
}
Esempio n. 4
0
func (w *window) SetCharCallback(f func(Key, bool)) {
	glfw.SetCharCallback(func(key, state int) {
		f(Key(key), state == 1)
	})
}
Esempio n. 5
0
func BindKeyboard() {
	glfw.SetCharCallback(takeKeyAction)
	glfw.Enable(glfw.KeyRepeat)
}