1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-12-24 19:18:12 -05:00

common: generate atlas in y rather than x direction (#126)

This lets us generate atlases that are more "square"ish,
and thus less likely to hit the graphics card boundaries
for texture dimensions.

Fixes #121.
This commit is contained in:
Robin Eklind 2019-11-09 22:33:09 -06:00 committed by Tim Sarbin
parent 948ca1fc1a
commit 09e713b1cb

View File

@ -141,13 +141,13 @@ func CreateSprite(data []byte, palette PaletteRec) *Sprite {
totalHeight := 0
frame := 0
for d := 0; d < int(result.Directions); d++ {
curMaxHeight := 0
curMaxWidth := 0
for f := 0; f < int(result.FramesPerDirection); f++ {
totalWidth += int(result.Frames[frame].Width)
curMaxHeight = int(Max(uint32(curMaxHeight), result.Frames[frame].Height))
curMaxWidth = int(Max(uint32(curMaxWidth), result.Frames[frame].Width))
totalHeight += int(result.Frames[frame].Height)
frame++
}
totalHeight += curMaxHeight
totalWidth += curMaxWidth
}
result.atlas, _ = ebiten.NewImage(totalWidth, totalHeight, ebiten.FilterNearest)
result.atlasBytes = make([]byte, totalWidth*totalHeight*4)
@ -155,15 +155,15 @@ func CreateSprite(data []byte, palette PaletteRec) *Sprite {
curX := 0
curY := 0
for d := 0; d < int(result.Directions); d++ {
curMaxHeight := 0
curMaxWidth := 0
for f := 0; f < int(result.FramesPerDirection); f++ {
curMaxHeight = int(Max(uint32(curMaxHeight), result.Frames[frame].Height))
curMaxWidth = int(Max(uint32(curMaxWidth), result.Frames[frame].Width))
result.Frames[frame].Image = result.atlas.SubImage(image.Rect(curX, curY, curX+int(result.Frames[frame].Width), curY+int(result.Frames[frame].Height))).(*ebiten.Image)
curX += int(result.Frames[frame].Width)
curY += int(result.Frames[frame].Height)
frame++
}
curY += curMaxHeight
curX = 0
curX += curMaxWidth
curY = 0
}
return result
}