mirror of
https://github.com/lloeki/ld48-29.git
synced 2025-12-06 11:04:39 +01:00
extract sprite
This commit is contained in:
parent
7691c1520d
commit
656ced6742
4 changed files with 68 additions and 12 deletions
62
ld48-29.go
62
ld48-29.go
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
|
"syscall"
|
||||||
"image"
|
"image"
|
||||||
"image/png"
|
"image/png"
|
||||||
gl "github.com/go-gl/gl"
|
gl "github.com/go-gl/gl"
|
||||||
|
|
@ -16,6 +17,24 @@ import (
|
||||||
var _ = pa.Initialize // TODO: remove later
|
var _ = pa.Initialize // TODO: remove later
|
||||||
|
|
||||||
|
|
||||||
|
// iterate faster
|
||||||
|
|
||||||
|
func rerun() (err error) {
|
||||||
|
log.Println("rerun")
|
||||||
|
gopath := os.Getenv("GOPATH")
|
||||||
|
env := []string{"GOPATH=" + gopath}
|
||||||
|
args := []string{"go", "run", "ld48-29.go"}
|
||||||
|
err = syscall.Exec("/usr/local/bin/go", args, env)
|
||||||
|
log.Fatal(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func reexec() {
|
||||||
|
err := rerun()
|
||||||
|
if err != nil { panic(err) }
|
||||||
|
}
|
||||||
|
|
||||||
// glfw callbacks
|
// glfw callbacks
|
||||||
|
|
||||||
func onError(err glfw.ErrorCode, desc string) {
|
func onError(err glfw.ErrorCode, desc string) {
|
||||||
|
|
@ -28,6 +47,10 @@ func onKey(window *glfw.Window, k glfw.Key, s int, action glfw.Action, mods glfw
|
||||||
}
|
}
|
||||||
|
|
||||||
switch glfw.Key(k) {
|
switch glfw.Key(k) {
|
||||||
|
case glfw.KeyR:
|
||||||
|
if mods & glfw.ModSuper != 0 {
|
||||||
|
reexec()
|
||||||
|
}
|
||||||
case glfw.KeyEscape:
|
case glfw.KeyEscape:
|
||||||
window.SetShouldClose(true)
|
window.SetShouldClose(true)
|
||||||
default:
|
default:
|
||||||
|
|
@ -74,6 +97,33 @@ func readTexture(r io.Reader) (texId gl.Texture, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func spriteQuad(x int, y int, w int, h int) {
|
||||||
|
size := 256
|
||||||
|
unit := 16
|
||||||
|
|
||||||
|
x1 := x * unit
|
||||||
|
y1 := y * unit
|
||||||
|
x2 := x * unit + w * unit
|
||||||
|
y2 := y * unit + h * unit
|
||||||
|
|
||||||
|
rx1 := float32(x1) / float32(size)
|
||||||
|
rx2 := float32(x2) / float32(size)
|
||||||
|
ry1 := float32(y1) / float32(size)
|
||||||
|
ry2 := float32(y2) / float32(size)
|
||||||
|
|
||||||
|
gl.MatrixMode(gl.MODELVIEW)
|
||||||
|
gl.Begin(gl.QUADS)
|
||||||
|
gl.Normal3f(0, 0, 1)
|
||||||
|
gl.TexCoord2f(rx1, ry1)
|
||||||
|
gl.Vertex3f(-1.0, -1.0, 1.0)
|
||||||
|
gl.TexCoord2f(rx2, ry1)
|
||||||
|
gl.Vertex3f(1.0, -1.0, 1.0)
|
||||||
|
gl.TexCoord2f(rx2, ry2)
|
||||||
|
gl.Vertex3f(1.0, 1.0, 1.0)
|
||||||
|
gl.TexCoord2f(rx1, ry2)
|
||||||
|
gl.Vertex3f(-1.0, 1.0, 1.0)
|
||||||
|
gl.End()
|
||||||
|
}
|
||||||
|
|
||||||
// main
|
// main
|
||||||
|
|
||||||
|
|
@ -132,17 +182,7 @@ func setup() (textures map[string]gl.Texture, lists map[string]uint) {
|
||||||
|
|
||||||
quad := gl.GenLists(1)
|
quad := gl.GenLists(1)
|
||||||
gl.NewList(quad, gl.COMPILE)
|
gl.NewList(quad, gl.COMPILE)
|
||||||
gl.Begin(gl.QUADS)
|
spriteQuad(0, 0, 4, 4)
|
||||||
gl.Normal3f(0, 0, 1)
|
|
||||||
gl.TexCoord2f(0, 0)
|
|
||||||
gl.Vertex3f(-1.0, -1.0, 1.0)
|
|
||||||
gl.TexCoord2f(0.5, 0)
|
|
||||||
gl.Vertex3f(1.0, -1.0, 1.0)
|
|
||||||
gl.TexCoord2f(0.5, 0.5)
|
|
||||||
gl.Vertex3f(1.0, 1.0, 1.0)
|
|
||||||
gl.TexCoord2f(0, 0.5)
|
|
||||||
gl.Vertex3f(-1.0, 1.0, 1.0)
|
|
||||||
gl.End()
|
|
||||||
gl.EndList()
|
gl.EndList()
|
||||||
|
|
||||||
lists["test"] = quad
|
lists["test"] = quad
|
||||||
|
|
|
||||||
18
log.mdown
18
log.mdown
|
|
@ -48,8 +48,24 @@ All time is CEST
|
||||||
|
|
||||||
- 11:57
|
- 11:57
|
||||||
|
|
||||||
And we have a spritesheet! 
|
And we have a spritesheet!
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
- 12:12
|
- 12:12
|
||||||
|
|
||||||
Taking a light break to stuff self.body with calories
|
Taking a light break to stuff self.body with calories
|
||||||
|
|
||||||
|
- 12:45
|
||||||
|
|
||||||
|
Short on supplies. Have to get out or risk falling down in 2 hours due to lack or carbohydrates in bloodstream.
|
||||||
|
|
||||||
|
- 14:12
|
||||||
|
|
||||||
|
Got sidetracked in reading Doom engine trivia
|
||||||
|
|
||||||
|
- 15:21
|
||||||
|
|
||||||
|
Getting to terms with OpenGL. Sprite system coming along nicely
|
||||||
|
|
||||||
|

|
||||||
|
|
|
||||||
BIN
screenshots/2.png
Normal file
BIN
screenshots/2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 MiB |
BIN
spritesheet.png
BIN
spritesheet.png
Binary file not shown.
|
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 6.9 KiB |
Loading…
Add table
Add a link
Reference in a new issue