mirror of
https://github.com/lloeki/ld48-29.git
synced 2025-12-06 11:04:39 +01:00
mouse pointer
This commit is contained in:
parent
5248b6b778
commit
fa33347cbf
3 changed files with 61 additions and 5 deletions
47
ld48-29.go
47
ld48-29.go
|
|
@ -18,6 +18,12 @@ import (
|
||||||
|
|
||||||
var _ = pa.Initialize // TODO: remove later
|
var _ = pa.Initialize // TODO: remove later
|
||||||
|
|
||||||
|
const (
|
||||||
|
INPUT_UP = 0
|
||||||
|
INPUT_DOWN = 1
|
||||||
|
INPUT_LEFT = 2
|
||||||
|
INPUT_RIGHT = 3
|
||||||
|
)
|
||||||
|
|
||||||
// iterate faster
|
// iterate faster
|
||||||
|
|
||||||
|
|
@ -53,8 +59,14 @@ func onKey(input chan int, window *glfw.Window, k glfw.Key, s int, action glfw.A
|
||||||
if mods & glfw.ModSuper != 0 {
|
if mods & glfw.ModSuper != 0 {
|
||||||
reexec()
|
reexec()
|
||||||
}
|
}
|
||||||
case glfw.KeyUp, glfw.KeyDown, glfw.KeyLeft, glfw.KeyRight:
|
case glfw.KeyUp:
|
||||||
input <- 1
|
input <- INPUT_UP
|
||||||
|
case glfw.KeyDown:
|
||||||
|
input <- INPUT_DOWN
|
||||||
|
case glfw.KeyLeft:
|
||||||
|
input <- INPUT_LEFT
|
||||||
|
case glfw.KeyRight:
|
||||||
|
input <- INPUT_RIGHT
|
||||||
case glfw.KeyEscape:
|
case glfw.KeyEscape:
|
||||||
window.SetShouldClose(true)
|
window.SetShouldClose(true)
|
||||||
default:
|
default:
|
||||||
|
|
@ -167,8 +179,8 @@ func main() {
|
||||||
go renderer(done, input)
|
go renderer(done, input)
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
_ = <- input
|
in := <- input
|
||||||
log.Print("input")
|
log.Printf("input %d", in)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
@ -178,6 +190,10 @@ func main() {
|
||||||
|
|
||||||
// renderer
|
// renderer
|
||||||
|
|
||||||
|
var mouseX float64
|
||||||
|
var mouseY float64
|
||||||
|
var mouseVisible bool
|
||||||
|
|
||||||
func renderer(done chan int, input chan int) {
|
func renderer(done chan int, input chan int) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
|
|
||||||
|
|
@ -188,16 +204,26 @@ func renderer(done chan int, input chan int) {
|
||||||
}
|
}
|
||||||
defer glfw.Terminate()
|
defer glfw.Terminate()
|
||||||
|
|
||||||
|
glfw.WindowHint(glfw.Resizable, 0)
|
||||||
|
|
||||||
window, err := glfw.CreateWindow(640, 480, "LD48-29", nil, nil)
|
window, err := glfw.CreateWindow(640, 480, "LD48-29", nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.SetInputMode(glfw.Cursor, glfw.CursorHidden)
|
||||||
|
|
||||||
onKeyClosure := func (window *glfw.Window, k glfw.Key, s int, action glfw.Action, mods glfw.ModifierKey) {
|
onKeyClosure := func (window *glfw.Window, k glfw.Key, s int, action glfw.Action, mods glfw.ModifierKey) {
|
||||||
onKey(input, window, k, s, action, mods)
|
onKey(input, window, k, s, action, mods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMouseClosure := func (window *glfw.Window, x float64, y float64) {
|
||||||
|
mouseX, mouseY = x, 480 - y
|
||||||
|
mouseVisible = mouseX < 640 && mouseX >= 0 && mouseY < 480 && mouseY >= 0
|
||||||
|
}
|
||||||
|
|
||||||
window.SetKeyCallback(onKeyClosure)
|
window.SetKeyCallback(onKeyClosure)
|
||||||
|
window.SetCursorPositionCallback(onMouseClosure)
|
||||||
|
|
||||||
window.MakeContextCurrent()
|
window.MakeContextCurrent()
|
||||||
|
|
||||||
|
|
@ -218,10 +244,12 @@ func setup() (textures map[string]gl.Texture, lists map[string]uint) {
|
||||||
gl.Enable(gl.DEPTH_TEST)
|
gl.Enable(gl.DEPTH_TEST)
|
||||||
gl.Enable(gl.LIGHTING)
|
gl.Enable(gl.LIGHTING)
|
||||||
gl.Enable(gl.CULL_FACE)
|
gl.Enable(gl.CULL_FACE)
|
||||||
|
gl.Enable(gl.BLEND)
|
||||||
|
|
||||||
gl.ClearColor(0.0, 0.0, 0.5, 0)
|
gl.ClearColor(0.0, 0.0, 0.5, 0)
|
||||||
gl.ClearDepth(1)
|
gl.ClearDepth(1)
|
||||||
gl.DepthFunc(gl.LEQUAL)
|
gl.DepthFunc(gl.LEQUAL)
|
||||||
|
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
|
||||||
|
|
||||||
textures = map[string]gl.Texture{}
|
textures = map[string]gl.Texture{}
|
||||||
lists = map[string]uint{}
|
lists = map[string]uint{}
|
||||||
|
|
@ -241,6 +269,13 @@ func setup() (textures map[string]gl.Texture, lists map[string]uint) {
|
||||||
|
|
||||||
lists["test"] = quad
|
lists["test"] = quad
|
||||||
|
|
||||||
|
quad = gl.GenLists(1)
|
||||||
|
gl.NewList(quad, gl.COMPILE)
|
||||||
|
spriteQuad(2, 0, 1, 1)
|
||||||
|
gl.EndList()
|
||||||
|
|
||||||
|
lists["cursor"] = quad
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -321,4 +356,8 @@ func render(textures map[string]gl.Texture, lists map[string]uint) {
|
||||||
x = (math.Sin(a) + 1) / 2 * float64(width)
|
x = (math.Sin(a) + 1) / 2 * float64(width)
|
||||||
y = (math.Cos(a) + 1) / 2 * float64(height)
|
y = (math.Cos(a) + 1) / 2 * float64(height)
|
||||||
drawSprite(textures["sprites"], x, y, -a, lists["test"])
|
drawSprite(textures["sprites"], x, y, -a, lists["test"])
|
||||||
|
|
||||||
|
if mouseVisible {
|
||||||
|
drawSprite(textures["sprites"], mouseX, mouseY, 0, lists["cursor"])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
17
log.mdown
17
log.mdown
|
|
@ -97,3 +97,20 @@ All time is CEST
|
||||||
- 20:34
|
- 20:34
|
||||||
|
|
||||||
Going concurrent. Goroutines, channels and closures make passing input events outside the locked OpenGL thread *really* easy.
|
Going concurrent. Goroutines, channels and closures make passing input events outside the locked OpenGL thread *really* easy.
|
||||||
|
|
||||||
|
- 20:51
|
||||||
|
|
||||||
|
Time for another break. Calories needed.
|
||||||
|
|
||||||
|
- 21:30
|
||||||
|
|
||||||
|
Back to jamming! ... on and off.
|
||||||
|
|
||||||
|
- 23:45
|
||||||
|
|
||||||
|
Managed to do some mouse tracking with sprite pointer
|
||||||
|
|
||||||
|
- 10:39
|
||||||
|
|
||||||
|
Moved out to nearby Starbucks. Connection is crappy, but back to jamming.
|
||||||
|
|
||||||
|
|
|
||||||
BIN
spritesheet.png
BIN
spritesheet.png
Binary file not shown.
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 7 KiB |
Loading…
Add table
Add a link
Reference in a new issue