From 8c5051dd4f3855a8ff0dfdd0f85728ffd095c5f6 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Thu, 20 Dec 2018 20:31:43 -0800 Subject: [PATCH] start work on wrapping sdl --- formats/dat/dat.go | 4 ++-- graphics/texture.go | 22 ++++++++++++++++++++++ tools/dc6/dc6.go | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 graphics/texture.go diff --git a/formats/dat/dat.go b/formats/dat/dat.go index 20c2c5d..20181a6 100644 --- a/formats/dat/dat.go +++ b/formats/dat/dat.go @@ -7,7 +7,7 @@ import ( ) type Palette struct { - Colors [256]imageColor.NRGBA + Colors [256]imageColor.RGBA } type color struct { @@ -24,7 +24,7 @@ func NewFromReader(reader io.Reader) (*Palette, error) { palette := new(Palette) for i, color := range colors { - palette.Colors[i] = imageColor.NRGBA{color.R, color.G, color.B, 0xff} + palette.Colors[i] = imageColor.RGBA{color.R, color.G, color.B, 0xff} } return palette, nil diff --git a/graphics/texture.go b/graphics/texture.go new file mode 100644 index 0000000..b72106f --- /dev/null +++ b/graphics/texture.go @@ -0,0 +1,22 @@ +package graphics + +import ( + "image/color" + "unsafe" + + "github.com/veandco/go-sdl2/sdl" +) + +func NewSurfaceFromRgba(colors []color.RGBA, width, height int) (*sdl.Surface, error) { + return sdl.CreateRGBSurfaceFrom( + unsafe.Pointer(&colors[0]), + int32(width), + int32(height), + 32, + width*4, + 0x000000ff, + 0x0000ff00, + 0x00ff0000, + 0xff000000, + ) +} diff --git a/tools/dc6/dc6.go b/tools/dc6/dc6.go index df44d1b..dc76542 100644 --- a/tools/dc6/dc6.go +++ b/tools/dc6/dc6.go @@ -39,7 +39,7 @@ func extractSprite(spritePath string, palette *dat.Palette, targetDir string) er for di, direction := range sprite.Directions { for fi, frame := range direction.Frames { - img := image.NewNRGBA(image.Rect(0, 0, frame.Width, frame.Height)) + img := image.NewRGBA(image.Rect(0, 0, frame.Width, frame.Height)) for y := 0; y < frame.Height; y++ { for x := 0; x < frame.Width; x++ { img.Set(x, y, palette.Colors[frame.Data[y*frame.Width+x]])