getting frame scrubber working, something is wrong with direction still
This commit is contained in:
parent
723f55186b
commit
d38188da95
@ -86,6 +86,7 @@ func (w *Window) advance() {
|
|||||||
|
|
||||||
w.scene.Advance(w)
|
w.scene.Advance(w)
|
||||||
|
|
||||||
|
w.sdlWindow.GLMakeCurrent(w.sdlGlContext)
|
||||||
imgui.Render()
|
imgui.Render()
|
||||||
imgui_backend.Render(w.displaySize(), w.bufferSize(), imgui.RenderedDrawData())
|
imgui_backend.Render(w.displaySize(), w.bufferSize(), imgui.RenderedDrawData())
|
||||||
w.sdlWindow.GLSwap()
|
w.sdlWindow.GLSwap()
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
"image/color"
|
"image/color"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
imgui "github.com/FooSoft/imgui-go"
|
imgui "github.com/FooSoft/imgui-go"
|
||||||
"github.com/FooSoft/lazarus/formats/dat"
|
"github.com/FooSoft/lazarus/formats/dat"
|
||||||
@ -30,40 +33,54 @@ func loadSprite(path string) (*dc6.Sprite, error) {
|
|||||||
return dc6.NewFromReader(fp)
|
return dc6.NewFromReader(fp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadTexture(window *platform.Window, spritePath, palettePath string) (*platform.Texture, error) {
|
|
||||||
sprite, err := loadSprite(spritePath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
palette, err := loadPalette(palettePath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
frame := sprite.Directions[0].Frames[0]
|
|
||||||
colors := make([]color.RGBA, frame.Width*frame.Height)
|
|
||||||
for y := 0; y < frame.Height; y++ {
|
|
||||||
for x := 0; x < frame.Width; x++ {
|
|
||||||
colors[y*frame.Width+x] = palette.Colors[frame.Data[y*frame.Width+x]]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return window.CreateTextureRgba(colors, frame.Width, frame.Height)
|
|
||||||
}
|
|
||||||
|
|
||||||
type scene struct {
|
type scene struct {
|
||||||
|
sprite *dc6.Sprite
|
||||||
|
palette *dat.Palette
|
||||||
texture *platform.Texture
|
texture *platform.Texture
|
||||||
|
|
||||||
|
directionIndex int32
|
||||||
|
frameIndex int32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *scene) Init(window *platform.Window) error {
|
func (s *scene) Init(window *platform.Window) error {
|
||||||
var err error
|
return nil
|
||||||
s.texture, err = loadTexture(window, "/home/alex/loadingscreen.dc6", "/home/alex/pal.dat")
|
}
|
||||||
return err
|
|
||||||
|
func (s *scene) Shutdown(window *platform.Window) error {
|
||||||
|
if s.texture == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.texture.Destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *scene) Advance(window *platform.Window) error {
|
func (s *scene) Advance(window *platform.Window) error {
|
||||||
imgui.Text("Hello")
|
var (
|
||||||
|
directionIndex = s.directionIndex
|
||||||
|
frameIndex = s.frameIndex
|
||||||
|
)
|
||||||
|
|
||||||
|
direction := s.sprite.Directions[directionIndex]
|
||||||
|
if imgui.SliderInt("Direction", &directionIndex, 0, int32(len(s.sprite.Directions))-1) {
|
||||||
|
frameIndex = 0
|
||||||
|
}
|
||||||
|
frame := direction.Frames[frameIndex]
|
||||||
|
imgui.SliderInt("Frame", &frameIndex, 0, int32(len(direction.Frames))-1)
|
||||||
|
|
||||||
|
if s.texture == nil || directionIndex != s.directionIndex || frameIndex != s.frameIndex {
|
||||||
|
colors := make([]color.RGBA, frame.Width*frame.Height)
|
||||||
|
for y := 0; y < frame.Height; y++ {
|
||||||
|
for x := 0; x < frame.Width; x++ {
|
||||||
|
colors[y*frame.Width+x] = s.palette.Colors[frame.Data[y*frame.Width+x]]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
s.texture, err = window.CreateTextureRgba(colors, frame.Width, frame.Height)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window.RenderTexture(
|
window.RenderTexture(
|
||||||
s.texture,
|
s.texture,
|
||||||
@ -71,18 +88,50 @@ func (s *scene) Advance(window *platform.Window) error {
|
|||||||
math.Rect4i{X: 0, Y: 0, W: 256, H: 256},
|
math.Rect4i{X: 0, Y: 0, W: 256, H: 256},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
s.directionIndex = directionIndex
|
||||||
|
s.frameIndex = frameIndex
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *scene) Shutdown(window *platform.Window) error {
|
func main() {
|
||||||
return s.texture.Destroy()
|
var (
|
||||||
|
palettePath = flag.String("palette", "", "path to palette file")
|
||||||
|
)
|
||||||
|
|
||||||
|
flag.Usage = func() {
|
||||||
|
fmt.Fprintf(os.Stderr, "Usage: %s [options] file\n", filepath.Base(os.Args[0]))
|
||||||
|
fmt.Fprintf(os.Stderr, "Parameters:\n\n")
|
||||||
|
flag.PrintDefaults()
|
||||||
|
}
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if flag.NArg() < 1 {
|
||||||
|
flag.Usage()
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
sprite, err := loadSprite(flag.Arg(0))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
palette := new(dat.Palette)
|
||||||
|
if len(*palettePath) > 0 {
|
||||||
|
palette, err = loadPalette(*palettePath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
|
||||||
platform.Init()
|
platform.Init()
|
||||||
defer platform.Shutdown()
|
defer platform.Shutdown()
|
||||||
|
|
||||||
window, err := platform.CreateWindow("Viewer", 1280, 720, new(scene))
|
scene := &scene{sprite: sprite, palette: palette}
|
||||||
|
window, err := platform.CreateWindow("Viewer", 1280, 720, scene)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user