本文整理汇总了Golang中github.com/go-gl/glfw3.PollEvents函数的典型用法代码示例。如果您正苦于以下问题:Golang PollEvents函数的具体用法?Golang PollEvents怎么用?Golang PollEvents使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PollEvents函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
glfw.SetErrorCallback(glfwError)
if !glfw.Init() {
log.Printf("Unable to initializer glfw")
return
}
defer glfw.Terminate()
window, err := glfw.CreateWindow(Width, Height, Title, nil, nil)
if err != nil {
panic(err)
}
window.MakeContextCurrent()
window.SetSizeCallback(fixProjection)
err = initGL()
if err != nil {
log.Printf("Error initializing OpenGL. %v", err)
panic(err)
}
glfw.SwapInterval(1)
fixProjection(window, Width, Height)
meshBuff := createMeshBuffer()
for !window.ShouldClose() {
timeDelta.Tick()
log.Printf("Time: %v", timeDelta.Delta)
window.SwapBuffers()
glfw.PollEvents()
}
}
开发者ID:andrebq,项目名称:exp,代码行数:34,代码来源:main.go
示例2: main
func main() {
fmt.Println("Init GLFW3")
if glfw3.Init() {
fmt.Println("Init ok")
defer closeGLFW()
}
// Create the window
fmt.Println("Opening window")
win, err := glfw3.CreateWindow(1024, 768, "Kunos Rulez", nil, nil)
gl.Init()
if err != nil {
fmt.Println(err)
} else {
fmt.Println("ok", win)
}
win.MakeContextCurrent()
for win.ShouldClose() == false {
glfw3.PollEvents()
gl.ClearColor(1.0, 0.0, 0.0, 1.0)
gl.Clear(gl.COLOR_BUFFER_BIT)
win.SwapBuffers()
}
fmt.Println("Destroying win")
win.Destroy()
}
开发者ID:kunos,项目名称:tutorials,代码行数:30,代码来源:glfw.go
示例3: main
func main() {
if !glfw.Init() {
log.Fatal("glfw failed to initialize")
}
defer glfw.Terminate()
window, err := glfw.CreateWindow(640, 480, "Deformable", nil, nil)
if err != nil {
log.Fatal(err.Error())
}
window.MakeContextCurrent()
glfw.SwapInterval(1)
window.SetMouseButtonCallback(handleMouseButton)
window.SetKeyCallback(handleKeyDown)
window.SetInputMode(glfw.Cursor, glfw.CursorHidden)
gl.Init()
initGL()
i := 16
m = GenerateMap(1600/i, 1200/i, i)
for running && !window.ShouldClose() {
x, y := window.GetCursorPosition()
if drawing != 0 {
m.Add(int(x)+int(camera[0]), int(y)+int(camera[1]), drawing, brushSizes[currentBrushSize])
}
gl.Clear(gl.COLOR_BUFFER_BIT)
gl.LoadIdentity()
gl.PushMatrix()
gl.PushAttrib(gl.CURRENT_BIT | gl.ENABLE_BIT | gl.LIGHTING_BIT | gl.POLYGON_BIT | gl.LINE_BIT)
gl.Translatef(-camera[0], -camera[1], 0)
m.Draw()
gl.PopAttrib()
gl.PopMatrix()
gl.PushAttrib(gl.COLOR_BUFFER_BIT)
gl.LineWidth(2)
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.ONE_MINUS_DST_COLOR, gl.ZERO)
// gl.Enable(gl.LINE_SMOOTH)
// gl.Hint(gl.LINE_SMOOTH_HINT, gl.NICEST)
gl.Translatef(float32(x), float32(y), 0)
gl.EnableClientState(gl.VERTEX_ARRAY)
gl.VertexPointer(2, gl.DOUBLE, 0, cursorVerts)
gl.DrawArrays(gl.LINE_LOOP, 0, 24)
gl.PopAttrib()
window.SwapBuffers()
glfw.PollEvents()
}
}
开发者ID:sixthgear,项目名称:deformable,代码行数:60,代码来源:main.go
示例4: main
func main() {
glfw.SetErrorCallback(errorCallback)
if !glfw.Init() {
panic("Can't init glfw")
}
defer glfw.Terminate()
window, err := glfw.CreateWindow(640, 480, "Testing", nil, nil)
if err != nil {
panic(err)
}
window.MakeContextCurrent()
window.SetSizeCallback(copiedReshape)
window.SetKeyCallback(keyHandler)
copiedInit()
running := true
for running && !window.ShouldClose() {
//copiedDrawCube(angle)
redraw()
window.SwapBuffers()
glfw.PollEvents()
running = window.GetKey(glfw.KeyEscape) == glfw.Release
}
}
开发者ID:srm88,项目名称:blocks,代码行数:27,代码来源:main.go
示例5: main
func main() {
glfw.SetErrorCallback(glfwErrorCallback)
if !glfw.Init() {
panic("failed to initialize glfw")
}
defer glfw.Terminate()
glfw.WindowHint(glfw.Resizable, glfw.False)
glfw.WindowHint(glfw.ContextVersionMajor, 2)
glfw.WindowHint(glfw.ContextVersionMinor, 1)
window, err := glfw.CreateWindow(800, 600, "Cube", nil, nil)
if err != nil {
panic(err)
}
window.MakeContextCurrent()
if err := gl.Init(); err != nil {
panic(err)
}
texture = newTexture("square.png")
defer gl.DeleteTextures(1, &texture)
setupScene()
for !window.ShouldClose() {
drawScene()
window.SwapBuffers()
glfw.PollEvents()
}
}
开发者ID:jasonrpowers,项目名称:glow,代码行数:30,代码来源:legacy_cube.go
示例6: main
func main() {
glfw.SetErrorCallback(errorCallback)
if !glfw.Init() {
panic("Can't init glfw!")
}
defer glfw.Terminate()
window, err := glfw.CreateWindow(Width, Height, Title, nil, nil)
if err != nil {
panic(err)
}
window.MakeContextCurrent()
glfw.SwapInterval(1)
gl.Init()
if err := initScene(); err != nil {
fmt.Fprintf(os.Stderr, "init: %s\n", err)
return
}
defer destroyScene()
for !window.ShouldClose() {
drawScene()
window.SwapBuffers()
glfw.PollEvents()
}
}
开发者ID:nzlov,项目名称:examples,代码行数:31,代码来源:gopher.go
示例7: onTick
func onTick(programState programState, dt uint64) (programState, bool) {
glfw.PollEvents()
keepTicking := !programState.Gl.Window.ShouldClose()
if keepTicking {
// Read raw inputs.
keys := programState.Gl.glfwKeyEventList.Freeze()
// Analyze the inputs, see what they mean.
commands := commands(keys)
// One of these commands may correspond to an action of the player's actor.
// We take it out so that we can process it in the IA phase.
// The remaining commands are kept for further processing.
playerAction, commands := commandsToAction(commands, programState.World.Player_id)
// Evolve the program one step.
programState.World.Time += dt // No side effect, we own a copy.
// $$$ THERE COULD BE SIDE EFFECTS HERE ACTUALLY: IF I GAVE A POINTER
// TO THE WORLD OR PROGRAM STATE TO SOMETHING. NEED TO CORRECT THAT.
programState = executeCommands(programState, commands)
//
programState.World = runAI(programState.World, playerAction)
// render on screen.
render(programState)
programState.Gl.Window.SwapBuffers()
}
return programState, keepTicking
}
开发者ID:Niriel,项目名称:daggor,代码行数:25,代码来源:main.go
示例8: main
func main() {
runtime.LockOSThread()
if !glfw.Init() {
fmt.Fprintf(os.Stderr, "Can't open GLFW")
return
}
defer glfw.Terminate()
glfw.WindowHint(glfw.Samples, 4)
glfw.WindowHint(glfw.ContextVersionMajor, 3)
glfw.WindowHint(glfw.ContextVersionMinor, 3)
glfw.WindowHint(glfw.OpenglProfile, glfw.OpenglCoreProfile)
glfw.WindowHint(glfw.OpenglForwardCompatible, glfw.True) // needed for macs
window, err := glfw.CreateWindow(1024, 768, "Tutorial 1", nil, nil)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
return
}
window.MakeContextCurrent()
gl.Init()
gl.GetError() // Ignore error
window.SetInputMode(glfw.StickyKeys, 1)
gl.ClearColor(0., 0., 0.4, 0.)
// Equivalent to a do... while
for ok := true; ok; ok = (window.GetKey(glfw.KeyEscape) != glfw.Press && !window.ShouldClose()) {
window.SwapBuffers()
glfw.PollEvents()
}
}
开发者ID:krux02,项目名称:mathgl,代码行数:35,代码来源:main.go
示例9: Continue
func (a *Application) Continue() bool {
glfw.PollEvents()
if a.window.ShouldClose() {
return false
}
a.update()
return true
}
开发者ID:james4k,项目名称:go-bgfx-examples,代码行数:8,代码来源:example.go
示例10: 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
示例11: eventLoop
func eventLoop(g *Game) {
eventTicker := time.NewTicker(time.Millisecond * 10)
for {
select {
case <-eventTicker.C:
do(func() {
glfw.PollEvents()
})
}
}
}
开发者ID:remogatto,项目名称:mozaik,代码行数:12,代码来源:main_init.go
示例12: UntilClose
func (t *Testbed) UntilClose(drawingFunction func()) {
for !t.window.ShouldClose() {
glfw.PollEvents()
gl.Clear(gl.COLOR_BUFFER_BIT)
drawingFunction()
t.window.SwapBuffers()
}
t.window.Destroy()
}
开发者ID:joonazan,项目名称:sprite,代码行数:13,代码来源:drawing_test.go
示例13: Run
// Run starts the main loop.
func (e *E) Run() error {
if !e.IsInitialized() {
return fmt.Errorf("not initialized")
}
if err := e.state.Init(e); err != nil {
return err
}
if state, ok := e.state.(Resizer); ok {
width, height := e.window.GetFramebufferSize()
state.Resize(width, height)
}
const dt = 1.0 / 60.0
for { // FIXME: lock graphics timestep
var _ = mgl64.Clamp
var _ = time.Now()
if state, ok := e.state.(Updater); ok {
if err := state.Update(dt); err != nil {
return err
}
}
if state, ok := e.state.(Renderer); ok {
if err := state.Render(); err != nil {
return err
}
}
glfw3.PollEvents()
if e.window.ShouldClose() {
if state, ok := e.state.(Closer); ok {
if err := state.Close(); err != nil {
return err
}
}
return nil
}
e.window.SwapBuffers()
}
return nil
}
开发者ID:niksaak,项目名称:goticles,代码行数:48,代码来源:engine.go
示例14: ListenForEvents
// ListenForEvents should be called by your main function, and will
// block indefinitely. This is necessary because some platforms expect
// calls from the main thread.
func ListenForEvents() error {
// ensure we have at least 2 procs, due to the thread conditions we
// have to work with.
procs := runtime.GOMAXPROCS(0)
if procs < 2 {
runtime.GOMAXPROCS(2)
}
glfw.Init()
defer glfw.Terminate()
setupGlfw()
t0 := time.Now()
for {
select {
case fn, ok := <-mainc:
if !ok {
return nil
}
fn()
default:
// when under heavy activity, sleep and poll instead to
// lessen sysmon() churn in Go's scheduler. with this
// method, OS X's Activity Monitor reports over 1000 sleeps
// a second, which is ridiculous, but better than 3000.
// haven't been able to create a minimal reproduction of
// this, but when tweaking values in runtime/proc.c's sysmon
// func, it is obvious this is a scheduler issue.
// TODO: best workaround is probably to write this entire
// loop in C, which should keep the sysmon thread from
// waking up (from these syscalls, anyways).
dt := time.Now().Sub(t0)
if dt < 150*time.Millisecond {
time.Sleep(15 * time.Millisecond)
glfw.PollEvents()
} else {
t0 = time.Now()
glfw.WaitEvents()
}
}
}
return nil
}
开发者ID:james4k,项目名称:exp,代码行数:46,代码来源:run.go
示例15: Start
func (self *Window) Start() chan bool {
now := time.Now()
// This is the ever important draw goroutine
go func() {
// super important
runtime.LockOSThread()
ctx := vg.NewContext()
for !self.window.ShouldClose() {
// gl.Enable(gl.BLEND)
// gl.Enable(gl.LINE_SMOOTH)
// gl.Hint(gl.LINE_SMOOTH_HINT, gl.NICEST)
// gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
w, h := self.Size()
self.SetBounds(0, 0, float64(w), float64(h))
if time.Since(now) > 2*time.Second {
debug = true
self.Draw(ctx)
debug = false
now = time.Now()
} else {
self.Draw(ctx)
}
self.window.SwapBuffers()
glfw.PollEvents()
// var total gl.Int
// gl.GetIntegerv(0x9048, &total)
// var available gl.Int
// gl.GetIntegerv(0x9049, &available)
// fmt.Println(total, available)
}
glfw.Terminate()
self.endchan <- true
}()
return self.endchan
}
开发者ID:xormplus,项目名称:ui-1,代码行数:42,代码来源:window.go
示例16: main
func main() {
if !glfw.Init() {
f.Println("Failed to init glfw")
panic("Cannot initialize glfw library")
}
defer glfw.Terminate()
//glfw.WindowHint(glfw.DepthBits, 16)
window, err := glfw.CreateWindow(300, 300, "Wander", nil, nil)
if err != nil {
panic(err)
}
window.SetFramebufferSizeCallback(reshape)
window.SetKeyCallback(key)
window.MakeContextCurrent()
glfw.SwapInterval(1)
width, height := window.GetFramebufferSize()
reshape(window, width, height)
if gl.Init() != 0 {
panic("Failed to init GL")
}
prog := setupProgram()
defer prog.Delete()
prog.Use()
attr = prog.GetAttribLocation("offset")
setup()
for !window.ShouldClose() {
if shouldRender() {
draw()
}
animate()
window.SwapBuffers()
glfw.PollEvents()
}
}
开发者ID:JoshWillik,项目名称:GoWander,代码行数:41,代码来源:wander.go
示例17: main
func main() {
glfw.SetErrorCallback(errorCallback)
if !glfw.Init() {
panic("Can't init glfw!")
}
defer glfw.Terminate()
window, err := glfw.CreateWindow(640, 480, "Testing", nil, nil)
if err != nil {
panic(err)
}
window.MakeContextCurrent()
for !window.ShouldClose() {
//Do OpenGL stuff
window.SwapBuffers()
glfw.PollEvents()
}
}
开发者ID:LonelyPale,项目名称:go-opengl,代码行数:21,代码来源:main.go
示例18: main
func main() {
if !glfw.Init() {
panic("Failed to initialize GLFW")
}
defer glfw.Terminate()
glfw.WindowHint(glfw.DepthBits, 16)
window, err := glfw.CreateWindow(300, 300, "Gears", nil, nil)
if err != nil {
panic(err)
}
// Set callback functions
window.SetFramebufferSizeCallback(reshape)
window.SetKeyCallback(key)
window.MakeContextCurrent()
glfw.SwapInterval(1)
width, height := window.GetFramebufferSize()
reshape(window, width, height)
// Parse command-line options
Init()
// Main loop
for !window.ShouldClose() {
// Draw gears
draw()
// Update animation
animate()
// Swap buffers
window.SwapBuffers()
glfw.PollEvents()
}
}
开发者ID:nzlov,项目名称:examples,代码行数:40,代码来源:gears.go
示例19: RunGamehost
func RunGamehost() {
if !glfw.Init() {
panic("Cannot init GLFW")
}
defer glfw.Terminate()
window, err := glfw.CreateWindow(800, 600, "Apollo", nil, nil)
if err != nil {
panic(err)
}
window.MakeContextCurrent()
gamehost_Window = window
gl.ClearColor(1, 1, 1, 1)
glu.LookAt(0, 1.5, 5, 0, 0, 0, 0, 1, 0)
frame := 0
EvaluateString("(trigger GAMEHOST Init!)", MainContext)
gamehost_world.Create(CreateCube(0, 0, 0))
for !gamehost_Window.ShouldClose() {
gl.Clear(gl.COLOR_BUFFER_BIT)
gl.LoadIdentity()
gamehost_Window.SetTitle(fmt.Sprintf("Frame #%v", frame))
frame++
EvaluateString("(gameloop 0.016)", MainContext)
gamehost_world.Render()
graphicsQueue.Process()
gamehost_Window.SwapBuffers()
glfw.PollEvents()
}
EvaluateString("(trigger GAMEHOST Shutdown!)", MainContext)
}
开发者ID:Bunkerbewohner,项目名称:gamelisp,代码行数:40,代码来源:gamehost.go
示例20: main
func main() {
// initialize glfw
if !glfw.Init() {
panic("Failed to initialize GLFW")
}
defer glfw.Terminate()
// create window
window, err := glfw.CreateWindow(600, 600, os.Args[0], nil, nil)
if err != nil {
panic(err)
}
window.SetFramebufferSizeCallback(onResize)
window.MakeContextCurrent()
// set up opengl context
onResize(window, 600, 600)
// set up physics
createBodies()
runtime.LockOSThread()
glfw.SwapInterval(1)
ticksToNextBall := 10
ticker := time.NewTicker(time.Second / 60)
for !window.ShouldClose() {
ticksToNextBall--
if ticksToNextBall == 0 {
ticksToNextBall = rand.Intn(100) + 1
addBall()
}
draw()
step(1.0 / 60.0)
window.SwapBuffers()
glfw.PollEvents()
<-ticker.C // wait up to 1/60th of a second
}
}
开发者ID:niksaak,项目名称:chipmunk,代码行数:40,代码来源:bouncing_balls.go
注:本文中的github.com/go-gl/glfw3.PollEvents函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论