예제 #1
1
// key events are a way to get input from GLFW.
func keyCallback(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
	//if u only want the on press, do = && && action == glfw.Press
	if key == glfw.KeyW && action == glfw.Press {
		fmt.Printf("W Pressed!\n")
		player.moveUp()
	}
	if key == glfw.KeyA { //&& action == glfw.Press
		fmt.Printf("A Pressed!\n")
		if action == glfw.Release {
			player.moving_left = false
		}
		if action == glfw.Press {
			player.moving_left = true
		}
		// player.moveLeft()
	}
	if key == glfw.KeyS {
		fmt.Printf("S Pressed!\n")
		player.moveDown()
	}
	if key == glfw.KeyD {
		fmt.Printf("D Pressed!\n")
		if action == glfw.Release {
			player.moving_right = false
		}
		if action == glfw.Press {
			player.moving_right = true
		}
		// player.moveRight()
	}

	if key == glfw.KeyEscape && action == glfw.Press {
		w.SetShouldClose(true)
	}
}
예제 #2
0
파일: state.go 프로젝트: egonelbre/spector
func (state *State) Render(window *glfw.Window) {
	if !state.Dirty {
		return
	}
	state.Dirty = false

	state.Reset(window)
	state.Time = time.Now()
	state.UpdateInput(window)

	hue := float32(state.Time.UnixNano()/1e6%360) / 360.0
	Highlight = ui.ColorHSLA(hue, 0.7, 0.7, 1.0)

	w, h := window.GetSize()
	root := &ui.Context{
		Backend: state.Backend,
		Input:   state.Input,
		Area:    ui.Block(0, 0, float32(w), float32(h)),
	}

	if root.Input.Mouse.Drag != nil {
		if !root.Input.Mouse.Drag(root) {
			root.Input.Mouse.Drag = nil
		}
	}

	state.Backend.SetBack(ui.ColorHex(0xEEEEEEFF))
	state.Backend.SetFore(ui.ColorHex(0xCCCCCCFF))
	state.Backend.SetFontColor(ui.ColorHex(0x000000FF))

	view := NewView(state, root, &state.Timeline)
	view.Render()
}
func programLoop(window *glfw.Window) {

	// the linked shader program determines how the data will be rendered
	shaders := compileShaders()
	shaderProgram := linkShaders(shaders)

	// VAO contains all the information about the data to be rendered
	VAO := createTriangleVAO()

	for !window.ShouldClose() {
		// poll events and call their registered callbacks
		glfw.PollEvents()

		// perform rendering
		gl.ClearColor(0.2, 0.5, 0.5, 1.0)
		gl.Clear(gl.COLOR_BUFFER_BIT)

		// draw loop
		gl.UseProgram(shaderProgram)      // ensure the right shader program is being used
		gl.BindVertexArray(VAO)           // bind data
		gl.DrawArrays(gl.TRIANGLES, 0, 3) // perform draw call
		gl.BindVertexArray(0)             // unbind data (so we don't mistakenly use/modify it)
		// end of draw loop

		// swap in the rendered buffer
		window.SwapBuffers()
	}
}
예제 #4
0
// key events are a way to get input from GLFW.
func keyCallback(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
	//if u only want the on press, do = && && action == glfw.Press
	player := game.Player

	if key == glfw.KeyW && action == glfw.Press {
		fmt.Printf("W Pressed!\n")
		player.Jump()

	}
	if key == glfw.KeyA { //&& action == glfw.Press
		fmt.Printf("A Pressed!\n")
		player.MoveLeft()
	}
	if key == glfw.KeyS {
		fmt.Printf("S Pressed!\n")
	}
	if key == glfw.KeyD {
		fmt.Printf("D Pressed!\n")
		player.MoveRight()

	}

	if key == glfw.KeyEscape && action == glfw.Press {
		w.SetShouldClose(true)
	}
}
예제 #5
0
파일: input.go 프로젝트: tbogdala/free
// mainKeyCallback is the main keyboard input callback for the game
func gameKeyCallback(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
	switch {
	// NOTE: For testing purposes, we'll exit on esc button
	case key == glfw.KeyEscape && action == glfw.Press:
		w.SetShouldClose(true)
	}
}
예제 #6
0
func keyCallback(window *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
	// When a user presses the escape key, we set the WindowShouldClose property to true,
	// which closes the application
	if key == glfw.KeyEscape && action == glfw.Press {
		window.SetShouldClose(true)
	}
}
예제 #7
0
func onKey(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
	switch {
	case key == glfw.KeyEscape && action == glfw.Press,
		key == glfw.KeyQ && action == glfw.Press:
		w.SetShouldClose(true)
	}
}
/* *****************  KEYBOARD INPUT ******************** */
func onKey(w *glfw.Window, key glfw.Key, scancode int,
	action glfw.Action, mods glfw.ModifierKey) {

	if key == glfw.KeyEscape && action == glfw.Press {
		fmt.Println("Close Window")
		w.SetShouldClose(true)
	}
}
예제 #9
0
파일: ui.go 프로젝트: egonelbre/spector
func (state *State) UpdateInput(window *glfw.Window) {
	state.Input.Update()

	x, y := window.GetCursorPos()
	state.Input.Mouse.Position.X = float32(x)
	state.Input.Mouse.Position.Y = float32(y)
	state.Input.Mouse.Down = window.GetMouseButton(glfw.MouseButtonLeft) == glfw.Press
}
예제 #10
0
파일: ballistic.go 프로젝트: tbogdala/cubez
func keyCallback(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
	// Key W == close app
	if key == glfw.KeyEscape && action == glfw.Press {
		w.SetShouldClose(true)
	}
	if key == glfw.KeySpace && action == glfw.Press {
		fire()
	}
}
예제 #11
0
func (c *chip8) setKeys(window *glfw.Window) {
	for k, v := range keyvalues {	
		if window.GetKey(k) == glfw.Release {
			c.key[v] = true
		} else {
			c.key[v] = false
		}
	}
}
예제 #12
0
func onFocus(w *glfw.Window, focused bool) {
	if !focused {
		for i := range Client.KeyState {
			Client.KeyState[i] = false
		}
	} else if lockMouse {
		w.SetInputMode(glfw.CursorMode, glfw.CursorDisabled)
	}
}
예제 #13
0
파일: demo.go 프로젝트: rdterner/gl
func drawScene(w *glfw.Window) {
	width, height := w.GetFramebufferSize()
	ratio := float32(width) / float32(height)
	var x1, x2, y1, y2 float32
	if ratio > 1 {
		x1, x2, y1, y2 = -ratio, ratio, -1, 1
	} else {
		x1, x2, y1, y2 = -1, 1, -1/ratio, 1/ratio
	}

	gl.Viewport(0, 0, int32(width), int32(height))
	gl.Clear(gl.COLOR_BUFFER_BIT)

	// Applies subsequent matrix operations to the projection matrix stack
	gl.MatrixMode(gl.PROJECTION)

	gl.LoadIdentity()                                                   // replace the current matrix with the identity matrix
	gl.Ortho(float64(x1), float64(x2), float64(y1), float64(y2), 1, -1) // multiply the current matrix with an orthographic matrix

	// Applies subsequent matrix operations to the modelview matrix stack
	gl.MatrixMode(gl.MODELVIEW)

	gl.LoadIdentity()

	gl.LineWidth(1)
	gl.Begin(gl.LINE)   // delimit the vertices of a primitive or a group of like primitives
	gl.Color3f(0, 0, 0) // set the current color
	gl.Vertex3f(0, y1, 0)
	gl.Vertex3f(0, y2, 0)
	gl.Vertex3f(x1, 0, 0)
	gl.Vertex3f(x2, 0, 0)
	gl.End()

	gl.Rotatef(float32(glfw.GetTime()*50), 0, 0, 1) // multiply the current matrix by a rotation matrix

	s := float32(.95)

	gl.Begin(gl.TRIANGLES)
	gl.Color3f(1, 0, 0)  // set the current color
	gl.Vertex3f(0, s, 0) // specify a vertex
	gl.Color3f(0, 1, 0)
	gl.Vertex3f(s*.866, s*-0.5, 0)
	gl.Color3f(0, 0, 1)
	gl.Vertex3f(s*-.866, s*-0.5, 0)
	gl.End()

	gl.LineWidth(5)
	gl.Begin(gl.LINE_LOOP)
	for i := float64(0); i < 2*math.Pi; i += .05 {
		r, g, b := hsb2rgb(float32(i/(2*math.Pi)), 1, 1)
		gl.Color3f(r, g, b)
		gl.Vertex3f(s*float32(math.Sin(i)), s*float32(math.Cos(i)), 0)
	}
	gl.End()

}
예제 #14
0
// onResize sets up a simple 2d ortho context based on the window size
func onResize(window *glfw.Window, w, h int) {
	w, h = window.GetSize() // query window to get screen pixels
	width, height := window.GetFramebufferSize()
	gl.Viewport(0, 0, int32(width), int32(height))
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, float64(w), 0, float64(h), -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.ClearColor(1, 1, 1, 1)
}
예제 #15
0
파일: triangle.go 프로젝트: depy/examples
func drawLoop(win *glfw.Window, vao uint32, shader uint32) {
	for !win.ShouldClose() {
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
		gl.BindVertexArray(vao)
		gl.UseProgram(shader)
		gl.DrawArrays(gl.TRIANGLES, 0, 3)

		glfw.PollEvents()
		win.SwapBuffers()
	}
}
예제 #16
0
func initOpenGl(window *glfw.Window, w, h int) {
	w, h = window.GetSize() // query window to get screen pixels
	width, height := window.GetFramebufferSize()
	gl.Viewport(0, 0, width, height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, float64(w), 0, float64(h), -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.ClearColor(.25, .88, .83, 1) // turquoise
}
예제 #17
0
func onKey(window *glfw.Window, k glfw.Key, s int, action glfw.Action, mods glfw.ModifierKey) {
	if action != glfw.Press {
		return
	}

	switch glfw.Key(k) {
	case glfw.KeyEscape:
		window.SetShouldClose(true)
	default:
		return
	}
}
예제 #18
0
func (c *chip8) Chip8_FX0A(window *glfw.Window) {
	//FX0A: A key press is awaited, and then stored in VX.
	glfw.WaitEvents()
	for k, v := range keyvalues {	
		if window.GetKey(k) == glfw.Press {
			c.v[(c.opcode & 0x0F00) >> 8] = v
			c.key[v] = true
			c.pc += 2
			break
		}
	}
}
예제 #19
0
func render(w *glfw.Window, program uint32) {
	gl.ClearColor(0, 0, 0, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.UseProgram(program)
	gl.BindVertexArray(firstSprite.GetVAO())
	gl.DrawArrays(gl.TRIANGLES, 0, 6)

	//Swap buffers
	w.SwapBuffers()
	glfw.PollEvents()
	gl.UseProgram(0)
}
예제 #20
0
파일: ui.go 프로젝트: egonelbre/spector
func (state *State) Reset(window *glfw.Window) {
	gl.ClearColor(1, 1, 1, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()

	gl.Disable(gl.DEPTH)
	gl.Enable(gl.FRAMEBUFFER_SRGB)

	width, height := window.GetSize()
	gl.Viewport(0, 0, int32(width), int32(height))
	gl.Ortho(0, float64(width), float64(height), 0, 30, -30)
}
예제 #21
0
파일: ui.go 프로젝트: egonelbre/spector
func (state *State) Render(window *glfw.Window) {
	state.Reset(window)
	state.UpdateInput(window)

	w, h := window.GetSize()
	root := &ui.Context{
		Backend: state.Backend,
		Input:   state.Input,
		Area:    ui.Block(0, 0, float32(w), float32(h)),
	}

	if root.Input.Mouse.Drag != nil {
		if !root.Input.Mouse.Drag(root) {
			root.Input.Mouse.Drag = nil
		}
	}

	state.Backend.SetBack(ui.ColorHex(0xEEEEEEFF))
	state.Backend.SetFore(ui.ColorHex(0xCCCCCCFF))
	state.Backend.SetFontColor(ui.ColorHex(0x000000FF))

	mm := &MainMenu{}
	ui.Buttons{
		{"☺", mm.File},
		{"Load", mm.Load},
		{"Save", mm.Save},
		{"Quit", mm.Quit},
	}.DoDynamic(ui.LayoutToRight(50, root.Top(20).Panel()))

	boxbounds := ui.Bounds{
		state.Box,
		state.Box.Offset(ui.Point{30, 30})}

	runtime.ReadMemStats(&state.MemStats)
	root.Right(state.SidePanelSize).Reflect("Mem", &state.MemStats)

	ui.SplitterX(root.Right(5), func(delta float32) {
		state.SidePanelSize -= delta
	})

	box := root.Child(boxbounds)
	box.Backend.SetBack(ui.ColorHex(0xFF88EEFF))
	box.Backend.SetFore(ui.ColorHex(0xFF88EEFF))
	box.Backend.Fill(box.Area)
	box.Backend.Stroke(box.Area)

	ui.DoDragXY(box, func(dx, dy float32) {
		state.Box.X += dx
		state.Box.Y += dy
	})
}
예제 #22
0
func keypress(window *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
	// Pressing escape will close the window
	if key == glfw.KeyEscape {
		window.SetShouldClose(true)
	}
	if action == glfw.Release {
		s := strconv.Itoa(scancode)
		if key == glfw.KeyA && mods == glfw.ModShift {
			fmt.Println("Key 'A' pressed!")
		} else if key == glfw.KeyA {
			fmt.Println("Key 'a' pressed!")
		} else {
			fmt.Println("Key '" + s + "' pressed!" + s)
		}
	}
}
예제 #23
0
func NewControllerManager(window *glfw.Window) *ControllerManager {
	var controllerList []Controller
	c := &ControllerManager{controllerList}
	window.SetKeyCallback(c.KeyCallback)
	window.SetMouseButtonCallback(c.MouseButtonCallback)
	window.SetCursorPosCallback(c.CursorPosCallback)
	window.SetScrollCallback(c.ScrollCallback)
	return c
}
예제 #24
0
파일: input.go 프로젝트: tbogdala/free
// inputUpdate handles input actions that are dependent on the delta between frames.
// (e.g. how much you move depends on the time delta since the last update)
func inputUpdate(w *glfw.Window, delta float32) {
	for key, cb := range activeKeyboard.keyBindings {
		if w.GetKey(key) == glfw.Press && cb != nil {
			cb(delta)
		}
	}

	// if the joystick is still connected, then we do the joystick polling
	// TODO: for now, we're just working with Joystick1 as hardcoded
	if glfw.JoystickPresent(glfw.Joystick1) {
		buttons := glfw.GetJoystickButtons(glfw.Joystick1)
		axes := glfw.GetJoystickAxes(glfw.Joystick1)

		//groggy.Logsf("DEBUG", "inputUpdate: %d %d %d %d %d   %d %d %d %d %d   %d %d %d %d ", buttons[0], buttons[1], buttons[2], buttons[3], buttons[4],
		// buttons[5], buttons[6], buttons[7], buttons[8], buttons[9],
		//	buttons[10], buttons[11], buttons[12], buttons[13])

		// process the buttons
		for buttonId, cb := range activeJoystick.buttonBindings {
			if buttons[buttonId] > 0 && cb != nil {
				cb(delta)
			}
		}

		// process the axis values
		for _, mapping := range activeJoystick.axisBindings {
			if mapping.Callback == nil {
				continue
			}

			v := axes[mapping.Id]
			if v >= mapping.Min && v <= mapping.Max {
				scale := mapping.Max - mapping.Min
				if mapping.NegativeMapping {
					// use the Max value here since NegativeMapping implies a negative ranage for the mapping
					v = (float32(math.Abs(float64(v))) - float32(math.Abs(float64(mapping.Max)))) / scale
				} else {
					v = (v - mapping.Min) / scale
				}
				mapping.Callback(delta * v)
			}
		} // axisBindings

	}
}
예제 #25
0
파일: graphics.go 프로젝트: tbogdala/free
// createRenderer creates a new graphics Renderer engine and does
// any initializiation necessary.
//
// NOTE: in the future, this can create either a forward or deferred
// renderer with more advanced options.
func createRenderer(mainWindow *glfw.Window) (*GameRenderer, error) {
	gr := new(GameRenderer)
	gr.Shaders = make(map[string]*fizzle.RenderShader)

	// create the renderer itself
	windowW, windowH := mainWindow.GetFramebufferSize()
	forwardRenderer := fizzle.NewForwardRenderer(mainWindow)
	forwardRenderer.Init(int32(windowW), int32(windowH))
	gr.Renderer = forwardRenderer
	gr.MainWindow = mainWindow

	// load the landscape diffuse shader
	shader, err := fizzle.LoadShaderProgramFromFiles(landscapeShaderPath, nil)
	if err != nil {
		return nil, fmt.Errorf("Failed to compile and link the diffuse shader program!\n%v", err)
	}
	gr.Shaders["landscape"] = shader

	// load the diffuse shader
	shader, err = fizzle.LoadShaderProgramFromFiles(diffuseShaderPath, nil)
	if err != nil {
		return nil, fmt.Errorf("Failed to compile and link the diffuse shader program!\n%v", err)
	}
	gr.Shaders["diffuse"] = shader

	// put a test light in the renderer
	light := fizzle.NewLight()
	//light.Position = mgl.Vec3{8.0, 8.0, 8.0}
	light.DiffuseColor = mgl.Vec4{1.0, 1.0, 1.0, 1.0}
	light.Direction = mgl.Vec3{0.1, -1.0, -0.1}
	light.DiffuseIntensity = 0.6
	light.AmbientIntensity = 0.4
	//light.Attenuation = 1.0
	forwardRenderer.ActiveLights[0] = light

	// setup the camera to look at the cube
	gr.camera = fizzle.NewOrbitCamera(mgl.Vec3{0.0, 0.0, 0.0}, mgl.DegToRad(35.0), 16.0, mgl.DegToRad(90.0))

	// set some OpenGL flags
	gl.Enable(gl.CULL_FACE)
	gl.Enable(gl.DEPTH_TEST)

	return gr, nil
}
예제 #26
0
파일: chat.go 프로젝트: num5/steven
func (c *ChatUI) handleKey(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
	if (key == glfw.KeyEscape || key == glfw.KeyEnter) && action == glfw.Release {
		if key == glfw.KeyEnter && len(c.inputLine) != 0 {
			Client.network.Write(&protocol.ChatMessage{string(c.inputLine)})
		}
		// Return control back to the default
		c.enteringText = false
		c.inputLine = c.inputLine[:0]
		lockMouse = true
		w.SetInputMode(glfw.CursorMode, glfw.CursorDisabled)
		w.SetCharCallback(nil)
		return
	}
	if key == glfw.KeyBackspace && action != glfw.Release {
		if len(c.inputLine) > 0 {
			c.inputLine = c.inputLine[:len(c.inputLine)-1]
		}
	}
}
예제 #27
0
func onKey(window *glfw.Window, k glfw.Key, s int, action glfw.Action, mods glfw.ModifierKey) {
	if action != glfw.Press {
		return
	}

	// disable if event handlers are flagged off
	if birdCollided && (k != glfw.KeyEscape) {
		return
	}

	switch glfw.Key(k) {
	case glfw.KeyEscape:
		window.SetShouldClose(true)
	case glfw.KeySpace:
		jump()
	default:
		return
	}
}
예제 #28
0
파일: events.go 프로젝트: pikkpoiss/twodee
func NewEventHandler(w *glfw.Window) (e *EventHandler) {
	e = &EventHandler{
		Events: make(chan Event, 100),
		window: w,
	}
	// See http://www.glfw.org/docs/latest/input.html#input_keyboard
	w.SetInputMode(glfw.StickyKeysMode, 1)
	w.SetCursorPosCallback(e.onMouseMove)
	w.SetKeyCallback(e.onKey)
	w.SetMouseButtonCallback(e.onMouseButton)
	return
}
예제 #29
0
func OnKey(window *glfw.Window, k glfw.Key, s int, action glfw.Action, mods glfw.ModifierKey) {
	if action != glfw.Press {
		return
	}
	nx, ny := game.PlayerX, game.PlayerY
	switch k {
	case glfw.KeyLeft:
		nx--
	case glfw.KeyRight:
		nx++
	case glfw.KeyUp:
		ny++
	case glfw.KeyDown:
		ny--
	case glfw.KeyEscape:
		window.SetShouldClose(true)
	}
	if nx >= 0 && nx < game.Width && ny >= 0 && ny < game.Height && game.Tiles[(ny*game.Width)+nx] == 226 {
		game.PlayerX, game.PlayerY = nx, ny
	}
}
예제 #30
0
func painalluksetOhjaimiksi(ikkuna *glfw.Window) (ohjaimet Ohjaimet) {

	ohjaimet.Kaasu = ikkuna.GetKey(glfw.KeyUp) == glfw.Press
	ohjaimet.Liipaisin = ikkuna.GetKey(glfw.KeySpace) == glfw.Press

	if ikkuna.GetKey(glfw.KeyLeft) == glfw.Press {
		ohjaimet.Ratti += 1
	}
	if ikkuna.GetKey(glfw.KeyRight) == glfw.Press {
		ohjaimet.Ratti -= 1
	}

	return
}