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

Image Load from a memory buffer #137

Open
donangel opened this issue Oct 12, 2022 · 1 comment
Open

Image Load from a memory buffer #137

donangel opened this issue Oct 12, 2022 · 1 comment

Comments

@donangel
Copy link

Hi everyone!

Here's my case: I plan to make a simple game using ImGUI. Since I'm very, very new to OpenGL, this library did catch my eye as a good, more understandable way to handle my simple 2D rendering needs.

I'm still researching theoretically (e.g., I didn't clone the code yet), and I cannot find a way to load an image using a memory buffer. Instead, it requires just a filename (which, under iOS/Android, may cause an issue).

Is there a way to modify/extend the lib to supply it with a memory buffer (where a PNG file's contents lie)? I couldn't find the IMG_Load source...

I really appreciate any help you can provide.

@tlrasor
Copy link
Contributor

tlrasor commented Dec 15, 2022

You're correct. It's not currently in simple2d but SDL does have support for it. The code loading images calls out directly to SDL_image library's IMG_Load function, (https://wiki.libsdl.org/SDL_image/IMG_Load). IMG_Load is only a light wrapper around SDL_RWops facilities, (https://wiki.libsdl.org/SDL2/SDL_RWops), and there is a helper even for handling loading from memory, SDL_RWFromMem (https://wiki.libsdl.org/SDL2/SDL_RWFromMem).

It would be simple but not completely trivial to add this functionality to simple2d.

For android/etc, SDL has special support for these platforms. I've not experimented with it myself but you can look into how the file handling is done on android here: https://github.com/libsdl-org/SDL/blob/8719a7653565443772b26c9e68025bc3a72d45f1/src/core/android/SDL_android.c#l681

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

2 participants