当前位置: 首页>>代码示例>>Golang>>正文


Golang glfw3.Window类代码示例

本文整理汇总了Golang中github.com/go-gl/glfw3.Window的典型用法代码示例。如果您正苦于以下问题:Golang Window类的具体用法?Golang Window怎么用?Golang Window使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Window类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: key

// 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
	}
}
开发者ID:nzlov,项目名称:examples,代码行数:27,代码来源:gears.go

示例2: Window

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
}
开发者ID:go3d,项目名称:go-ngine,代码行数:29,代码来源:ctx.go

示例3: NewSpriteDrawer

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
}
开发者ID:joonazan,项目名称:sprite,代码行数:28,代码来源:drawer.go

示例4: keyHandler

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)
	}
}
开发者ID:fatman2021,项目名称:mapeditor,代码行数:10,代码来源:main.go

示例5: onResize

// 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)
}
开发者ID:niksaak,项目名称:chipmunk,代码行数:12,代码来源:bouncing_balls.go

示例6: KeyPress

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)
		}
	}
}
开发者ID:neurocase,项目名称:physicstest,代码行数:12,代码来源:main.go

示例7: mouseButtonCallback

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),
		}
	}
}
开发者ID:kebo,项目名称:gorgasm,代码行数:16,代码来源:callback.go

示例8: Open

// 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)
}
开发者ID:james4k,项目名称:exp,代码行数:19,代码来源:glfw.go

示例9: onKey

// 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:

	}
}
开发者ID:spacetug,项目名称:raytracer,代码行数:20,代码来源:main.go

示例10: New

// 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
}
开发者ID:james4k,项目名称:exp,代码行数:22,代码来源:glfw.go

示例11: key

// 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
	}
}
开发者ID:nzlov,项目名称:gogl,代码行数:40,代码来源:10.go

示例12: runGameLoop

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)
			}
		}
	}
}
开发者ID:JamesClonk,项目名称:asteroids,代码行数:58,代码来源:main.go

示例13: key

// 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
	}
}
开发者ID:nzlov,项目名称:gogl,代码行数:24,代码来源:09.go

示例14: keyEvent

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))

}
开发者ID:nick-fedesna,项目名称:egles,代码行数:36,代码来源:main.go

示例15: Init

// 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}
}
开发者ID:kebo,项目名称:gorgasm,代码行数:20,代码来源:callback.go


注:本文中的github.com/go-gl/glfw3.Window类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。