Exemplo n.º 1
0
Arquivo: main.go Projeto: sycoso/glfw
func main() {
	var err error
	if err = glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.Terminate()

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

	defer glfw.CloseWindow()

	glfw.SetWindowTitle("Draw")
	glfw.SetSwapInterval(1)
	glfw.SetKeyCallback(onKey)
	glfw.SetMouseButtonCallback(onMouseBtn)
	glfw.SetWindowSizeCallback(onResize)

	running = true
	for running && glfw.WindowParam(glfw.Opened) == 1 {
		if mouse[0] != 0 {
			pen.lineTo(glfw.MousePos())
		} else {
			pen.moveTo(glfw.MousePos())
		}

		glfw.SwapBuffers()
	}
}
Exemplo n.º 2
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
}
Exemplo n.º 3
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()
	}
}
Exemplo n.º 4
0
Arquivo: main.go Projeto: 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
	}
}
Exemplo n.º 5
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
	}
}
Exemplo n.º 6
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()
	})
}
Exemplo n.º 7
0
Arquivo: input.go Projeto: vron/fm
func initInput() {
	// Start listening to mouse events
	glfw.SetMouseButtonCallback(click)
	glfw.SetMousePosCallback(move)
}
Exemplo n.º 8
0
func initInput() {
	glfw.SetKeyCallback(onKey)
	glfw.SetMouseButtonCallback(onMouseBttn)
	glfw.SetMousePosCallback(onMousePos)
}
Exemplo n.º 9
0
func (w *window) SetMouseButtonCallback(f func(MouseButton, bool)) {
	glfw.SetMouseButtonCallback(func(button, state int) {
		f(MouseButton(button), state == 1)
	})
}
Exemplo n.º 10
0
func Init() {
	glfw.SetMouseWheelCallback(mouseWheelHandler)
	glfw.SetMouseButtonCallback(mouseButtonHandler)
	glfw.SetMousePosCallback(mousePosHandler)
	glfw.SetKeyCallback(keyHandler)
}