2018-12-18 02:16:52 +00:00
|
|
|
package main
|
|
|
|
|
2018-12-22 03:44:19 +00:00
|
|
|
import (
|
|
|
|
"image/color"
|
|
|
|
"log"
|
|
|
|
"os"
|
2018-12-18 02:16:52 +00:00
|
|
|
|
2018-12-22 03:44:19 +00:00
|
|
|
"github.com/FooSoft/lazarus/formats/dat"
|
|
|
|
"github.com/FooSoft/lazarus/formats/dc6"
|
|
|
|
"github.com/FooSoft/lazarus/graphics"
|
|
|
|
"github.com/veandco/go-sdl2/sdl"
|
|
|
|
)
|
|
|
|
|
|
|
|
func loadPalette(path string) (*dat.Palette, error) {
|
|
|
|
fp, err := os.Open(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer fp.Close()
|
|
|
|
return dat.NewFromReader(fp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func loadSprite(path string) (*dc6.Sprite, error) {
|
|
|
|
fp, err := os.Open(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer fp.Close()
|
|
|
|
return dc6.NewFromReader(fp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func loadSurface(spritePath, palettePath string) (*sdl.Surface, 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]]
|
|
|
|
}
|
2018-12-18 02:16:52 +00:00
|
|
|
}
|
|
|
|
|
2018-12-22 03:44:19 +00:00
|
|
|
return graphics.NewSurfaceFromRgba(colors, frame.Width, frame.Height)
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
window, err := sdl.CreateWindow("Viewer", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, 800, 600, sdl.WINDOW_SHOWN)
|
2018-12-18 02:16:52 +00:00
|
|
|
if err != nil {
|
2018-12-22 03:44:19 +00:00
|
|
|
log.Fatal(err)
|
2018-12-18 02:16:52 +00:00
|
|
|
}
|
|
|
|
defer window.Destroy()
|
|
|
|
|
2018-12-22 03:44:19 +00:00
|
|
|
renderer, err := sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer renderer.Destroy()
|
|
|
|
|
|
|
|
sprite, err := loadSurface("/home/alex/loadingscreen.dc6", "/home/alex/pal.dat")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
texture, err := renderer.CreateTextureFromSurface(sprite)
|
2018-12-18 02:16:52 +00:00
|
|
|
if err != nil {
|
2018-12-22 03:44:19 +00:00
|
|
|
log.Fatal(err)
|
2018-12-18 02:16:52 +00:00
|
|
|
}
|
|
|
|
|
2018-12-22 03:44:19 +00:00
|
|
|
renderer.Clear()
|
|
|
|
renderer.Copy(texture, &sdl.Rect{0, 0, 256, 256}, &sdl.Rect{0, 0, 256, 256})
|
|
|
|
renderer.Present()
|
2018-12-18 02:16:52 +00:00
|
|
|
|
2018-12-22 03:44:19 +00:00
|
|
|
for running := true; running; {
|
2018-12-18 02:16:52 +00:00
|
|
|
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
|
|
|
|
switch event.(type) {
|
|
|
|
case *sdl.QuitEvent:
|
|
|
|
running = false
|
|
|
|
break
|
|
|
|
}
|
2018-12-22 03:44:19 +00:00
|
|
|
sdl.Delay(1)
|
2018-12-18 02:16:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|