You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide a convenient way to convert to Surface's pixel format #61
Suppose I want to fill a rectangle with some color. FillRect member function expects a color in surface's format. There is conversion function, SDL_MapRGB, but it expects SDL_PixelFormat*. Surface::GetFormat, however, returns only SDL_PixelFormat::format, not the whole structure.
What is the preferred way to convert RGB values to surface's color that FillRect expects?
surface.FillRect(rect, SDL_MapRGB(???, r, g, b));
Shall a method be provided to convert RGB to color value:
Yes, I've had that in plans. Not yet figured out a consistent way to handle both integer pixelformat and SDL_PixelFormat structure everywhere (renderer, texture, surface). Regarding the color, MapRGB should likely be a method of a SDL_PixelFormat wrapper. I'll try to handle this next year :)
Activity
ooxi commentedon Dec 30, 2015
👍
AMDmi3 commentedon Dec 30, 2015
Yes, I've had that in plans. Not yet figured out a consistent way to handle both integer pixelformat and SDL_PixelFormat structure everywhere (renderer, texture, surface). Regarding the color, MapRGB should likely be a method of a SDL_PixelFormat wrapper. I'll try to handle this next year :)
ilyapopov commentedon Dec 30, 2015
Is this a correct workaround?
ilyapopov commentedon Dec 30, 2015
Or better this:
AMDmi3 commentedon Dec 30, 2015
You don't have to allocate a new pixel format as Surface already contains one.
Probably something like this:
ilyapopov commentedon Dec 30, 2015
Thanks! I did not realize i can access
formatthroughGet().