本文整理汇总了Golang中github.com/go-gl/glfw/v3/1/glfw.Window类的典型用法代码示例。如果您正苦于以下问题:Golang Window类的具体用法?Golang Window怎么用?Golang Window使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Window类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
}
开发者ID:jhautefeuille,项目名称:hellochipmunk,代码行数:36,代码来源:glfwtest.go
示例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()
}
开发者ID:egonelbre,项目名称:spector,代码行数:33,代码来源:state.go
示例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()
}
}
开发者ID:cstegel,项目名称:opengl-samples-golang,代码行数:28,代码来源:hello_triangle.go
示例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)
}
}
开发者ID:jhautefeuille,项目名称:hellochipmunk,代码行数:27,代码来源:main.go
示例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)
}
}
开发者ID:tbogdala,项目名称:free,代码行数:8,代码来源:input.go
示例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)
}
}
开发者ID:cstegel,项目名称:opengl-samples-golang,代码行数:7,代码来源:hello_window.go
示例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)
}
}
开发者ID:maleck13,项目名称:jigsaws,代码行数:7,代码来源:helloworldgl.go
示例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)
}
}
开发者ID:Ozzadar,项目名称:golang-vr-opengl-engine,代码行数:9,代码来源:LeftRightColorOculusDK2.go
示例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
}
开发者ID:egonelbre,项目名称:spector,代码行数:8,代码来源:ui.go
示例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()
}
}
开发者ID:tbogdala,项目名称:cubez,代码行数:9,代码来源:ballistic.go
示例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
}
}
}
开发者ID:CJKinni,项目名称:Chip8-Emulator,代码行数:9,代码来源:main.go
示例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)
}
}
开发者ID:ammaraskar,项目名称:steven,代码行数:9,代码来源:desktop.go
示例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()
}
开发者ID:rdterner,项目名称:gl,代码行数:56,代码来源:demo.go
示例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)
}
开发者ID:jhautefeuille,项目名称:hellochipmunk,代码行数:12,代码来源:glfwtest.go
示例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()
}
}
开发者ID:depy,项目名称:examples,代码行数:11,代码来源:triangle.go
示例16: initOpenGl
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
}
开发者ID:himanshushekhar,项目名称:golang-flappybirdclone,代码行数:11,代码来源:main.go
示例17: onKey
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
}
}
开发者ID:Ariemeth,项目名称:frame-assault-2,代码行数:12,代码来源:engine.go
示例18: Chip8_FX0A
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
}
}
}
开发者ID:CJKinni,项目名称:Chip8-Emulator,代码行数:12,代码来源:main.go
示例19: render
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)
}
开发者ID:Ozzadar,项目名称:golang-vr-opengl-engine,代码行数:13,代码来源:main.go
示例20: Reset
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)
}
开发者ID:egonelbre,项目名称:spector,代码行数:13,代码来源:ui.go
注:本文中的github.com/go-gl/glfw/v3/1/glfw.Window类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论