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

Palette can't be modified #1362

Open
Henrique194 opened this issue Jan 8, 2024 · 0 comments
Open

Palette can't be modified #1362

Henrique194 opened this issue Jan 8, 2024 · 0 comments

Comments

@Henrique194
Copy link

Henrique194 commented Jan 8, 2024

Say we have a palette with 4 colors. This palette is used by a surface. If I wanted to modify color 1, I would do something like this in C:

SDL_Color color = {0xff, 0xff, 0xff, 0xff};
SDL_SetPaletteColors(surface->format->palette, &color, 1, 1);

In rust bindings we don't have a way to update the color 1, unless we resort to using unsafe rust and mimic the C code:

unsafe {
   let color = SDL_Color {
       r: 0xff,
       g: 0xff,
       b: 0xff,
       a: 0xff,
   };
   let mut colors = vec![color];
   let sdl_surface = *surface.raw();
   let pal = (*sdl_surface.format).palette;
   let colors_ptr = (&mut colors [0]) as *mut SDL_Color;
   
   sys::SDL_SetPaletteColors(pal, colors_ptr, 1, 1);
};

To solve this issue, we may need two new functions: one to retrieve the palette in the Surface struct and other to update the palette based on SDL_SetPaletteColors.
@Cobrand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants