Exemple #1
0
// Opens a new window.
func (c *Controller) Open(win *Window) (err error) {
	c.Win = win
	mode := glfw.Windowed
	if win.Fullscreen {
		mode = glfw.Fullscreen
	}
	if win.Resize == false {
		glfw.OpenWindowHint(glfw.WindowNoResize, 1)
	}
	if err = glfw.OpenWindow(win.Width, win.Height, 0, 0, 0, 0, 0, 0, mode); err != nil {
		return
	}
	gl.Init()
	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	v1, v2, v3 := glfw.GLVersion()
	log.Printf("OpenGL version: %v %v %v\n", v1, v2, v3)
	fb_supported := glfw.ExtensionSupported("GL_EXT_framebuffer_object")
	log.Printf("Framebuffer supported: %v\n", fb_supported)
	c.SetClearColor(0, 0, 0, 0)
	if win.VSync == true {
		glfw.SetSwapInterval(1) // Limit to refresh
	}
	glfw.SetWindowTitle(win.Title)
	glfw.SetWindowSizeCallback(func(w, h int) {
		log.Printf("Resizing window to %v, %v\n", w, h)
		c.resize()
	})
	err = c.resize()
	return
}
Exemple #2
0
func main() {
	fmt.Print("GLFW Init Start.")
	glfw.Init()
	fmt.Println(" GLFW Init Done.")

	defer glfw.Terminate()
	defer fmt.Println("example Terminating.")

	fmt.Println("GLFW Set Hints.")
	glfw.OpenWindowHint(glfw.WindowNoResize, 1)

	fmt.Print("GLFW Open Window Start.")
	glfw.OpenWindow(640, 480, 8, 8, 8, 0, 0, 0, glfw.Windowed)
	glfw.SetWindowTitle("example")
	fmt.Println(" GLFW Open Window Done.")

	v1, v2, v3 := glfw.GLVersion()
	fmt.Printf("OpenGL version: %d.%d.%d\n", v1, v2, v3)
	fmt.Printf("GLFW version: %d.%d.%d\n", glfw.VersionMajor, glfw.VersionMinor, glfw.VersionRevision)

	glfw.SetSwapInterval(1)

	fps := time.Duration(30)
	fmt.Printf("Creating %d Hz Ticker.", fps)
	ticker := time.NewTicker(time.Second / fps)
	fmt.Printf(" %d Hz Ticker Created\n", fps)

	closedWindow := glfwHelper.WindowCloseChan()
	mouseButtons := glfwHelper.MouseButtonChan()
	mousePos := glfwHelper.MousePosChan()
	mouseWheel := glfwHelper.MouseWheelChan()
	keyButtons := glfwHelper.KeyChan()
	charButtons := glfwHelper.CharChan()

	for {
		select {
		case <-ticker.C:
			glfw.SwapBuffers()
		case <-closedWindow:
			return
		case input := <-mouseButtons:
			fmt.Println(input)
		case input := <-mousePos:
			fmt.Println(input)
		case input := <-mouseWheel:
			fmt.Println(input)
		case input := <-keyButtons:
			fmt.Println(input)
		case input := <-charButtons:
			fmt.Println(string(input))
		}
	}
}