1 Star 0 Fork 0

陈慧颖/gooid

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main_glfw.go 1.82 KB
一键复制 编辑 原始数据 按行查看 历史
gooid 提交于 2019-04-19 15:34 +08:00 . Camera2Demo
// +build !android
package main
import (
"log"
"runtime"
"github.com/go-gl/glfw/v3.2/glfw"
)
var wMouseLeft = false
func CursorPosCallback(w *glfw.Window, x float64, y float64) {
mouseEvent(int(float32(x)/WINDOWSCALE), int(float32(y)/WINDOWSCALE), wMouseLeft)
}
func MouseButtonCallback(w *glfw.Window, button glfw.MouseButton, action glfw.Action, mod glfw.ModifierKey) {
x, y := w.GetCursorPos()
if button == glfw.MouseButtonLeft {
switch action {
case glfw.Press, glfw.Repeat:
wMouseLeft = true
case glfw.Release:
wMouseLeft = false
}
mouseEvent(int(float32(x)/WINDOWSCALE), int(float32(y)/WINDOWSCALE), wMouseLeft)
}
}
func FocusCallback(w *glfw.Window, focused bool) {
if !focused {
//destroyed()
} else {
//redraw()
}
}
func main() {
runtime.LockOSThread()
log.Printf("main ...")
if err := glfw.Init(); err != nil {
panic(err)
}
defer glfw.Terminate()
glfw.WindowHint(glfw.ContextVersionMajor, 2)
glfw.WindowHint(glfw.ContextVersionMinor, 0)
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
// 以下是指定用 EGL 和 OpenGL ES
glfw.WindowHint(glfw.ContextCreationAPI, glfw.EGLContextAPI)
glfw.WindowHint(glfw.ClientAPI, glfw.OpenGLESAPI)
w, err := glfw.CreateWindow(width, height, "Record", nil, nil)
if err != nil {
panic(err)
}
w.MakeContextCurrent()
curWin = w
width, height = w.GetSize()
preCreate(nil)
create()
postCreate(nil)
initEGL()
w.SetCursorPosCallback(CursorPosCallback)
w.SetMouseButtonCallback(MouseButtonCallback)
w.SetFocusCallback(FocusCallback)
for !w.ShouldClose() {
glfw.WaitEvents()
draw()
}
releaseEGL()
destroyed()
log.Printf("done")
}
var curWin *glfw.Window
const RECORDPATH = "./sdcard/records"
func getDensity() int { return density }
func SwapBuffers() { curWin.SwapBuffers() }
func Wake() { glfw.PostEmptyEvent() }
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/githubchy/gooid.git
git@gitee.com:githubchy/gooid.git
githubchy
gooid
gooid
2c72341a60e5

搜索帮助