start work on wrapping sdl

This commit is contained in:
Alex Yatskov 2018-12-20 20:31:43 -08:00
parent 87b9cf9967
commit 8c5051dd4f
3 changed files with 25 additions and 3 deletions

View File

@ -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

22
graphics/texture.go Normal file
View File

@ -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,
)
}

View File

@ -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]])