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

Pixel Format Enums are missing #81

Open
lukaslcf opened this issue Jan 27, 2025 · 3 comments
Open

Pixel Format Enums are missing #81

lukaslcf opened this issue Jan 27, 2025 · 3 comments

Comments

@lukaslcf
Copy link

I am trying to create texture using the texture creator of a canvas
let mut texture = creator.create_texture_target(PixelFormat::RGB24, 256, 240).unwrap();

However, there is no such const/enum called PixelFormat::RGB24.

Interestingly, it was mentioned in the documentation on create_texture_from_surface
let surface = Surface::new(512, 512, PixelFormat::RGB24).unwrap();

What is preferred way to do this for sdl3?

@revmischa
Copy link
Collaborator

Hm it may need to be added back

@ghtalpo
Copy link

ghtalpo commented Feb 2, 2025

I think you can try this for temporal workaround:

unsafe { PixelFormat::from_ll(SDL_PixelFormat::RGB24) },

@lukaslcf
Copy link
Author

lukaslcf commented Feb 3, 2025

My solution for this is using PixelFormat::try_from(SDL_PIXELFORMAT_RGB24).unwrap(). This avoids the use of unsafe. For production code I suppose you should handle the case where the pixel format is not available, but I am just using unwrap here.

Took inspiration from a code example that I couldn't find back atm :(

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

No branches or pull requests

3 participants