Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various font/image bugfixes #55

Merged
merged 3 commits into from
Oct 16, 2022
Merged

Conversation

compmstr
Copy link

@compmstr compmstr commented Sep 11, 2022

Use the sdl2 surface pitch when generating an OpenGL image
This should fix #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 #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.

Corey Williams added 3 commits September 11, 2022 08:19
…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.
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.
@compmstr compmstr changed the title Use the sdl2 surface pitch when generating an OpenGL image Various font/image bugfixes Sep 19, 2022
Copy link
Owner

@vydd vydd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@vydd vydd merged commit 528f223 into vydd:master Oct 16, 2022
@compmstr compmstr mentioned this pull request Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Text rendering problem with hello-world example Changed colors with load image
2 participants