-
Notifications
You must be signed in to change notification settings - Fork 491
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
Getting PixelFormat from PixelFormatEnum? #840
Comments
The following seems to work:
Swiped from https://stackoverflow.com/a/32000743/203487 |
Seems like there could be a helper in rust-sdl2 to help you do that without unsafe. I'm tagging it as functionality, if someone sees this and wants to make a PR, feel free! |
@Cobrand Hi, Is an Into trait implementation to go from |
I think it's fine to use unsafe here, as long as we guarantee ourselves that the code cannot fail according to the sdl2 doc. |
Color::to_u32()
requires a&PixelFormat
, but I've got aPixelFormatEnum
and I can't figure out how to convert it. There's aFrom
implementation forPixelFormat
toPixelFormatEnum
, but nothing the other way around as far as I can tell.The overall project here is drawing text with rusttype. Best I've figured is to get a
Color
for each pixel, ram them all in aVec<u32>
, pass that data as a&[u8]
toSurface::from_data()
, thenTextureCreator::create_texture_from_surface()
. If there's a better/simpler way, I'm all ears.The text was updated successfully, but these errors were encountered: