本文整理汇总了Golang中github.com/go-gl/glfw/v3/1/glfw.Window类的典型用法代码示例。如果您正苦于以下问题:Golang Window类的具体用法?Golang Window怎么用?Golang Window使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Window类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: keyCallback
// 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: Render
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()
}
示例3: programLoop
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: keyCallback
// 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: gameKeyCallback
// 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: keyCallback
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: onKey
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)
}
}
示例8: onKey
/* ***************** 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: UpdateInput
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: keyCallback
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: setKeys
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: onFocus
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: drawScene
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: 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, 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: drawLoop
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()
}
}