Skip to content

Commit

Permalink
gui: fix broken rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
cornelk committed Dec 15, 2024
1 parent a5e5897 commit 3130c7a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion gui/sdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/veandco/go-sdl2/sdl"
)

const bytesPerPixel = 4

func init() {
Setup = setupSDLGui
}
Expand Down Expand Up @@ -200,7 +202,7 @@ func renderSDL(dimensions Dimensions, backend Backend, renderer *sdl.Renderer, t
image := backend.Image()

data := unsafe.Pointer(&image.Pix[0])
if err := tex.Update(nil, data, dimensions.Width); err != nil {
if err := tex.Update(nil, data, dimensions.Width*bytesPerPixel); err != nil {
return false, err
}

Expand Down
4 changes: 3 additions & 1 deletion gui/sdl/sdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/retroenv/retrogolib/gui"
)

const bytesPerPixel = 4

// Setup initializes the SDL library and returns a render and cleanup function.
func Setup(backend gui.Backend) (guiRender func() (bool, error), guiCleanup func(), err error) {
dimensions := backend.Dimensions()
Expand Down Expand Up @@ -93,7 +95,7 @@ func renderSDL(dimensions gui.Dimensions, backend gui.Backend, renderer uintptr,
}

image := backend.Image()
if ret := UpdateTexture(tex, 0, image.Pix, dimensions.Width); ret != 0 {
if ret := UpdateTexture(tex, 0, image.Pix, dimensions.Width*bytesPerPixel); ret != 0 {
return false, fmt.Errorf("updating SDL texture: %s", GetError())
}

Expand Down

0 comments on commit 3130c7a

Please sign in to comment.