vydd / sketch

A Common Lisp framework for the creation of electronic art, visual design, game prototyping, game making, computer graphics, exploration of human-computer interaction, and more.
MIT License
1.4k stars 67 forks source link

Various font/image bugfixes #55

Closed compmstr closed 1 year ago

compmstr commented 1 year ago

Use the sdl2 surface pitch when generating an OpenGL image This should fix https://github.com/vydd/sketch/issues/51

I ended up seeing the same issue, and it turned out that the SDL surface pitch generated from sdl2-ttf was not being taken into account when sending the pixel data to OpenGL. Essentially there are sometimes gaps in the data because the sdl2 surface gets aligned to a power-of-two row length, instead of the number of bytes in each row.

I tested locally and it fixed the issue.

If the pitch ends up being the same as the width of the surface in pixels, this should still work fine.

2nd commit: This should fix https://github.com/vydd/sketch/issues/32

Fix handling of different byte orders on SDL_Surface when converting to GL texture

SDL_ttf is generating argb32 images, while loaded images are rgba to start with. With this change, we'll now convert the SDL surface to rgba32 if it's not that format already.

Note that previously text was working with :bgra, which is :argb in big-endian format. That's why I went with rgba32 vs rgba8888, which would have the wrong endianness. I tested all of this out to come to that conclustion.

Tested this change and both text and images are loading with the proper colors now.

3rd commit: Removed unused 'typeface' binding

Convert empty text lines to a single space since sdl2-ttf throws an error on an empty string. Converted to space instead of removing to keep line height formatting. This was causing issues with type errors from SBCL that ended up having empty lines on them. The error wouldn't display.