Exemplo n.º 1
0
// change view angle, exit upon ESC
func key(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.KeyZ:
		if mods&glfw.ModShift != 0 {
			view_rotz -= 5.0
		} else {
			view_rotz += 5.0
		}
	case glfw.KeyEscape:
		window.SetShouldClose(true)
	case glfw.KeyUp:
		view_rotx += 5.0
	case glfw.KeyDown:
		view_rotx -= 5.0
	case glfw.KeyLeft:
		view_roty += 5.0
	case glfw.KeyRight:
		view_roty -= 5.0
	default:
		return
	}
}
Exemplo n.º 2
0
Arquivo: ctx.go Projeto: go3d/go-ngine
func (me *context) Window(winf *ngctx.WinProfile, bufSize *ngctx.BufferBits, ctxProf *ngctx.CtxProfile) (window ngctx.Window, err error) {
	glfw.WindowHint(glfw.Samples, winf.MultiSampling)
	glfw.WindowHint(glfw.RedBits, bufSize.Color.R)
	glfw.WindowHint(glfw.GreenBits, bufSize.Color.G)
	glfw.WindowHint(glfw.BlueBits, bufSize.Color.B)
	glfw.WindowHint(glfw.AlphaBits, bufSize.Color.A)
	glfw.WindowHint(glfw.DepthBits, bufSize.Depth)
	glfw.WindowHint(glfw.StencilBits, bufSize.Stencil)
	glfw.WindowHint(glfw.ContextVersionMajor, ctxProf.Version.Major)
	glfw.WindowHint(glfw.ContextVersionMinor, ctxProf.Version.Minor)
	glfw.WindowHint(glfw.OpenglProfile, glfw.OpenglCoreProfile)
	if ctxProf.ForwardCompat {
		glfw.WindowHint(glfw.OpenglForwardCompatible, 1)
	}
	var mon *glfw.Monitor
	if winf.FullScreen {
		mon, err = glfw.GetPrimaryMonitor()
	}
	if err == nil {
		var win *glfw.Window
		if win, err = glfw.CreateWindow(winf.Width, winf.Height, winf.Title, mon, nil); win != nil {
			window = newWindow(win)
			if winf.FullScreen {
				win.SetInputMode(glfw.Cursor, glfw.CursorHidden)
			}
		}
	}
	return
}
Exemplo n.º 3
0
func NewSpriteDrawer(window *glfw.Window, layers int) *SpriteDrawer {
	s := new(SpriteDrawer)

	vao := gl.GenVertexArray()
	vao.Bind()

	s.Camera = vec2.Identity

	s.Program = CreateProgram("shaders/2d.vert", "shaders/2d.geom", "shaders/texture.frag")
	s.Use()
	s.camera_uniform = s.GetUniformLocation("camera")

	s.Texture = gl.GenTexture()
	s.Texture.Bind(gl.TEXTURE_2D_ARRAY)
	gl.TexImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.RGBA, 2048, 2048, layers, 0, gl.RGBA, gl.UNSIGNED_BYTE, nil)
	gl.TexParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.LINEAR)

	s.Window = window
	w, h := window.GetSize()
	s.OnScreenResize(w, h)

	s.Window.SetSizeCallback(func(window *glfw.Window, w, h int) {
		s.OnScreenResize(w, h)
	})

	return s
}
Exemplo n.º 4
0
func keyHandler(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)
	}
}
Exemplo n.º 5
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, 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(1, 1, 1, 1)
}
Exemplo n.º 6
0
func (game *Game) KeyPress(window *glfw.Window, k glfw.Key, s int, action glfw.Action, mods glfw.ModifierKey) {
	fmt.Println("keypress", k)
	if action == glfw.Release {
		switch k {

		case 77:
			fmt.Println("m")
		case glfw.KeyEscape:
			window.SetShouldClose(true)
		}
	}
}
Exemplo n.º 7
0
func mouseButtonCallback(
	window *glfw.Window,
	button glfw.MouseButton,
	action glfw.Action,
	mod glfw.ModifierKey) {

	if button == glfw.MouseButton1 {
		down := action == glfw.Press
		x, y := window.GetCursorPosition()
		event <- ActionUpDownEvent{
			Down: down,
			X:    float32(x),
			Y:    float32(y),
		}
	}
}
Exemplo n.º 8
0
Arquivo: glfw.go Projeto: james4k/exp
// Open opens a new OS window via GLFW.
func Open(width, height int, title string) (*Window, error) {
	var wnd *glfw3.Window
	errc := make(chan error)
	mainc <- func() {
		var err error
		wnd, err = glfw3.CreateWindow(width, height, title, nil, nil)
		errc <- err
		if err == nil {
			wnd.SetInputMode(glfw3.Cursor, glfw3.CursorNormal)
			wnd.Restore()
		}
	}
	err := <-errc
	if err != nil {
		return nil, err
	}
	return openFromWindow(wnd)
}
Exemplo n.º 9
0
// onKey handles key events.
func onKey(window *glfw.Window, key glfw.Key, code int, action glfw.Action, mod glfw.ModifierKey) {
	if action != glfw.Press {
		return
	}

	switch key {
	case glfw.KeyF5:
		shaderReload()

	case glfw.KeyEscape:
		window.SetShouldClose(true)

	case glfw.KeySpace:

	case glfw.KeyLeft:
	case glfw.KeyRight:

	}
}
Exemplo n.º 10
0
Arquivo: glfw.go Projeto: james4k/exp
// New creates a new OS window via GLFW as a ui.Environment.
func New(width, height int, title string) (ui.Environment, error) {
	var wnd *glfw.Window
	errc := make(chan error)
	mainc <- func() {
		var err error
		wnd, err = glfw.CreateWindow(width, height, title, nil, nil)
		errc <- err
		if err == nil {
			wnd.SetInputMode(glfw.Cursor, glfw.CursorNormal)
		}
	}
	err := <-errc
	if err != nil {
		return nil, err
	}
	w := &env{
		Window: wnd,
	}
	w.init()
	return w, nil
}
Exemplo n.º 11
0
Arquivo: 10.go Projeto: nzlov/gogl
// change view angle, exit upon ESC
func key(window *glfw.Window, k glfw.Key, s int, action glfw.Action, mods glfw.ModifierKey) {

	switch glfw.Key(k) {
	case glfw.KeyEscape:
		window.SetShouldClose(true)
	case glfw.KeyUp:
		xpos -= float32(math.Sin(float64(heading*piover180)) * 0.05)
		zpos -= float32(math.Cos(float64(heading*piover180)) * 0.05)
		if walkbiasangle >= 359.0 {
			walkbiasangle = 0.0
		} else {
			walkbiasangle += 10
		}
		walkbias = float32(math.Sin(float64(walkbiasangle*piover180)) / 20.0)
	case glfw.KeyDown:
		xpos += float32(math.Sin(float64(heading*piover180)) * 0.05)
		zpos += float32(math.Cos(float64(heading*piover180)) * 0.05)
		if walkbiasangle <= 1.0 {
			walkbiasangle = 359.0
		} else {
			walkbiasangle -= 10
		}
		walkbias = float32(math.Sin(float64(walkbiasangle*piover180)) / 20.0)
	case glfw.KeyLeft:
		heading += 1.0
		yrot = heading
	case glfw.KeyRight:
		heading -= 1.0
		yrot = heading
	case glfw.KeyPageUp:
		z -= 0.02
		lookupdown -= 1.0
	case glfw.KeyPageDown:
		z += 0.02
		lookupdown += 1.0
	default:
		return
	}
}
Exemplo n.º 12
0
func runGameLoop(window *glfw.Window) {
	for !window.ShouldClose() {
		// update objects
		updateObjects()

		// hit detection
		hitDetection()

		// ---------------------------------------------------------------
		// draw calls
		gl.Clear(gl.COLOR_BUFFER_BIT)

		drawCurrentScore()
		drawHighScore()

		if isGameWon() {
			drawWinningScreen()
		} else if isGameLost() {
			drawGameOverScreen()
		}

		// draw everything 9 times in a 3x3 grid stitched together for seamless clipping
		for x := -1.0; x < 2.0; x++ {
			for y := -1.0; y < 2.0; y++ {
				gl.MatrixMode(gl.MODELVIEW)
				gl.PushMatrix()
				gl.Translated(gameWidth*x, gameHeight*y, 0)

				drawObjects()

				gl.PopMatrix()
			}
		}

		gl.Flush()
		window.SwapBuffers()
		glfw.PollEvents()

		// switch resolution
		if altEnter {
			window.Destroy()

			fullscreen = !fullscreen
			var err error
			window, err = initWindow()
			if err != nil {
				panic(err)
			}

			altEnter = false

			gl.LineWidth(1)
			if fullscreen {
				gl.LineWidth(2)
			}
		}
	}
}
Exemplo n.º 13
0
Arquivo: 09.go Projeto: nzlov/gogl
// change view angle, exit upon ESC
func key(window *glfw.Window, k glfw.Key, s int, action glfw.Action, mods glfw.ModifierKey) {

	switch glfw.Key(k) {
	case glfw.KeyEscape:
		window.SetShouldClose(true)
	case glfw.KeyT:
		twinkle = !twinkle
	case glfw.KeyUp:
		tilt -= 0.5 // 屏幕向上倾斜
	case glfw.KeyDown:
		tilt += 0.5 // 屏幕向下倾斜
	case glfw.KeyLeft:
		ztilt -= 0.5 // 屏幕向上倾斜
	case glfw.KeyRight:
		ztilt += 0.5 // 屏幕向下倾斜
	case glfw.KeyPageUp:
		zoom -= 0.2 // 缩小
	case glfw.KeyPageDown:
		zoom += 0.2 // 放大
	default:
		return
	}
}
Exemplo n.º 14
0
func keyEvent(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
	switch key {
	case glfw.KeyEscape:
		w.SetShouldClose(true)
	case glfw.KeyLeft:
		if mods == glfw.ModShift {
			ModelView = ModelView.Mul4(mgl.HomogRotate3DY(5))
		} else {
			ModelView = ModelView.Mul4(mgl.Translate3D(-0.1, 0, 0))
		}
	case glfw.KeyRight:
		if mods == glfw.ModShift {
			ModelView = ModelView.Mul4(mgl.HomogRotate3DY(-5))
		} else {
			ModelView = ModelView.Mul4(mgl.Translate3D(0.1, 0, 0))
		}
	case glfw.KeyUp:
		if mods == glfw.ModShift {
			ModelView = ModelView.Mul4(mgl.HomogRotate3DX(5))
		} else {
			ModelView = ModelView.Mul4(mgl.Translate3D(0, 0.1, 0))
		}
	case glfw.KeyDown:
		if mods == glfw.ModShift {
			ModelView = ModelView.Mul4(mgl.HomogRotate3DX(-5))
		} else {
			ModelView = ModelView.Mul4(mgl.Translate3D(0, -0.1, 0))
		}
	case glfw.KeyMinus:
		ModelView = ModelView.Mul4(mgl.Translate3D(0, 0, -0.1))
	case glfw.KeyEqual:
		ModelView = ModelView.Mul4(mgl.Translate3D(0, 0, 0.1))
	}
	go func(m mgl.Mat4f) { MVP <- m }(Projection.Mul4(ModelView))

}
Exemplo n.º 15
0
// Init initializes a glfw.Window to be used in a xorg Gorgasm
// application. It has to be called after the GLFW initialization
// boilerplate. See
// https://github.com/remogatto/gorgasm-examples/triangle/src/triangle/main.go
// for an example.
func Init(window *glfw.Window) {

	glfw.SetErrorCallback(errorCallback)

	// Set callbacks associated with window events
	window.SetCloseCallback(exitCallback)
	window.SetMouseButtonCallback(mouseButtonCallback)
	window.SetCursorPositionCallback(cursorPositionCallback)

	// Begin sending events related to the creation process
	event <- CreateEvent{}
	event <- StartEvent{}
	event <- ResumeEvent{}
	event <- NativeWindowCreatedEvent{Window: window}
}
Exemplo n.º 16
0
func keyCallback(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
	if key == glfw.KeyEscape && action == glfw.Press {
		w.SetShouldClose(true)
	}
}
Exemplo n.º 17
0
func MouseCoord(window *glfw.Window, xpos, ypos float64) glm.Vec2d {
   width, height := window.GetSize()
   return glm.Vec2d{xpos / float64(width), 1 - ypos / float64(height)}
}
Exemplo n.º 18
0
func WindowAspectRatio(window *glfw.Window) float64 {
	frameWidth, frameHeight := window.GetFramebufferSize()
	return float64(frameWidth) / float64(frameHeight)
}
Exemplo n.º 19
0
func bindEvents(window *glfw.Window, delegate WindowDelegate) {
	window.SetFramebufferSizeCallback(delegate.Reshape)
	window.SetMouseButtonCallback(delegate.MouseClick)
	window.SetCursorPositionCallback(delegate.MouseMove)
	window.SetKeyCallback(delegate.KeyPress)
	window.SetScrollCallback(delegate.Scroll)
	window.SetCloseCallback(delegate.OnClose)
}
Exemplo n.º 20
0
func keyCallback(window *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
	//fmt.Printf("%v, %v, %v, %v\n", key, scancode, action, mods)

	if key == glfw.KeyEscape && action == glfw.Press {
		window.SetShouldClose(true)
	}

	if !paused {
		if key == glfw.KeyLeft {
			if action == glfw.Press {
				ship.RotateLeft(true)
			} else if action == glfw.Release {
				ship.RotateLeft(false)
			}
		} else if key == glfw.KeyRight {
			if action == glfw.Press {
				ship.RotateRight(true)
			} else if action == glfw.Release {
				ship.RotateRight(false)
			}
		}

		if key == glfw.KeyUp {
			if action == glfw.Press {
				ship.Accelerate(true)
			} else if action == glfw.Release {
				ship.Accelerate(false)
			}
		} else if key == glfw.KeyDown {
			if action == glfw.Press {
				ship.Decelerate(true)
			} else if action == glfw.Release {
				ship.Decelerate(false)
			}
		}

		if key == glfw.KeySpace || key == glfw.KeyX {
			if action == glfw.Press {
				ship.Shoot(true)
			} else if action == glfw.Release {
				ship.Shoot(false)
			}
		}

		if (key == glfw.KeyY || key == glfw.KeyZ || key == glfw.KeyLeftShift || key == glfw.KeyRightShift) && action == glfw.Press {
			ship.DropMine()
		}

		if (key == glfw.KeyC || key == glfw.KeyLeftControl || key == glfw.KeyRightControl) && action == glfw.Press {
			ship.ShootTorpedo()
		}
	}

	if key == glfw.KeyEnter && action == glfw.Press { //&& mods == glfw.ModAlt {
		altEnter = true
	}

	if key == glfw.KeyF1 && action == glfw.Press {
		switchHighscore()
	}

	if key == glfw.KeyF2 && action == glfw.Press {
		switchColors()
	}

	if key == glfw.KeyF3 && action == glfw.Press {
		switchWireframe()
	}

	if (key == glfw.KeyF9 || key == glfw.KeyR || key == glfw.KeyBackspace) && action == glfw.Press {
		score = 0
		resetGame()
	}

	if (key == glfw.KeyPause || key == glfw.KeyP) && action == glfw.Press {
		paused = !paused
	}

	if key == glfw.KeyN && action == glfw.Press && isGameWon() {
		difficulty += 3
		resetGame()
	}

	if debug && key == glfw.KeyF10 && action == glfw.Press {
		for _, asteroid := range asteroids {
			if asteroid.IsAlive() {
				asteroid.Destroy()
			}
		}
		for _, mine := range mines {
			if mine.IsAlive() {
				mine.Destroy()
			}
		}
	}
}
Exemplo n.º 21
0
func keyDown(window *glfw.Window, key glfw.Key) bool {
	return window.GetKey(key) == glfw.Press
}
Exemplo n.º 22
0
func SetWindow(wnd *glfw.Window) {
	hwnd := wnd.GetWin32Window()
	bgfx.SetWin32Window(uintptr(unsafe.Pointer(hwnd)))
}
Exemplo n.º 23
0
func (game *Game) KeyPress(window *glfw.Window, k glfw.Key, s int, action glfw.Action, mods glfw.ModifierKey) {
	//fmt.Println("keypress", k)
	if action == glfw.Release {
		switch k {

		case glfw.KeyEscape:
			window.SetShouldClose(true)
			//b key
		case 66:
			fmt.Println((len(BreadCrumbs) - 1), "Crumz")
			//if len(BreadCrumbs) < 1{
			for i := 0; i < len(BreadCrumbs)-1; i++ {
				fmt.Println(i, ":", BreadCrumbs[i])
				//	}
			}
			// > key
		case 46:
			LookAround(MazeMan)
			inspdir := FindLowestCell(Inspection)
			if deadend == 0 {
				dir := GridAtDirection(MazeMan, inspdir)
				SetManPos(dir)
				BreadCrumbs = append(BreadCrumbs, dir)
				goback = 0
			} else {
				fmt.Println("deadend, go back")
				b := len(BreadCrumbs)
				c := BreadCrumbs[b-1-goback]
				goback++
				SetManPos(c)
			}

		case 72:
			fmt.Println("Z: RESET|X: HEURISTIC|C: COMPUTEPATH|M:BRUSH|V:NEXTPOINT")

			//X key
		case 88:
			heur := GiveHeuristic(here)
			fmt.Println("Here:", here, "Heuristic:", heur, "Crumbs:", IsCrumbed(here))

			//v Key
		case 86:
			inspdir := FindLowestCell(Inspection)
			dir := GridAtDirection(MazeMan, inspdir)
			fmt.Println("next cell is", dir)
			//Z KEY
		case 90:
			BreadCrumbs = BreadCrumbs[:0]
			for i := 0; i < 400; i++ {
				if Grid[i] == 1 {
					Grid[i] = 0
				}
			}
			SetManPos(StartPos)
			fmt.Println("MazeMan sent to StartPos")

			//C KEY
		case 67:
			LookAround(MazeMan)
			fmt.Println("ComputePath")

			sortloc := FindLowestCell(Inspection)
			fmt.Println(sortloc)

			//M KEY
		case 77:
			SwitchMode()
			modeis := "wall"
			switch mode {
			case 0:
				modeis = "wall"
			case 1:
				modeis = "start position"
			case 2:
				modeis = "end position"
			}
			fmt.Println(modeis, "brush")
		//case 46:
		//fmt.Println("MOVE FORWARDS")
		case 44:
			fmt.Println("MOVE BACKWARDS")
		}
	}
}