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

Handle SDL surface formats #504

Open
JD557 opened this issue Jun 29, 2024 · 0 comments
Open

Handle SDL surface formats #504

JD557 opened this issue Jun 29, 2024 · 0 comments

Comments

@JD557
Copy link
Owner

JD557 commented Jun 29, 2024

Right now, SdlSurface expects all Surfaces to be SDL_PIXELFORMAT_RGBA32, which is a problem when interacting with other libraries, such as SDL image.

For example, to load an image, one needs to do:

  def loadImage(path: CString): RamSurface =
    val originalSurface = IMG_Load(path)
    if (originalSurface == null) throw new RuntimeException("Failed to load image")
    val formattedSurface = SDL_ConvertSurfaceFormat(originalSurface, SDL_PixelFormatEnum.SDL_PIXELFORMAT_RGBA32.uint, 0.toUInt)
    val ramSurface = SdlSurface.withRawData(formattedSurface)(_.toRamSurface())
    SDL_FreeSurface(originalSurface)
    SDL_FreeSurface(formattedSurface)
    ramSurface

There should at least be some helper to convert a Ptr[SDL_Surface] to a RamSurface and take care of converting the surface if needed and free any temporary objects.

A smart constructor (or multiple SdlSurface implementations that support different formats) could also be nice, as views over surfaces can also be broken.

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

1 participant