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

JPG support in raylib #4220

Open
paramita opened this issue Sep 8, 2024 · 11 comments
Open

JPG support in raylib #4220

paramita opened this issue Sep 8, 2024 · 11 comments

Comments

@paramita
Copy link

paramita commented Sep 8, 2024

It seems that raylib only supports PNG/GIF/QOI/DDS by default: https://github.com/raysan5/raylib/blob/master/src/config.h#L162
It was recently discussed at https://discord.com/channels/568138951836172421/568871298428698645/1263162072557162496

I started to learn odin and wanted to build the image viewer app, so I immediately faced that issue. I hope it's possible to widen the supported image formats. For example, enabling SVG support would be beneficial for building UI elements since the vector image can be scaled to any size.

The following warning is shown when loading jpg as Image or Texture2D:

INFO: FILEIO: [cat.jpg] File loaded successfully
WARNING: IMAGE: Data format not supported
WARNING: IMAGE: Failed to load image data
Texture{id = 0, width = 0, height = 0, mipmaps = 0, format = "UNKNOWN"}

Operating System & Odin Version:

Odin:    dev-2024-09-nightly:dd1f151
OS:      Windows 10 Unknown Edition (000000bf) (version: 21H2), build 19044.4780
CPU:     13th Gen Intel(R) Core(TM) i5-13600K
RAM:     32541 MiB
Backend: LLVM 18.1.8
@Feoramund
Copy link
Contributor

I haven't used our raylib bindings yet, but I imagine you could compile raylib with the configurations you want set to enabled and use the resulting library object instead of the one shipped with Odin. That might be a good workaround for now.

@Vonixxx
Copy link

Vonixxx commented Sep 9, 2024

I also needed JPG support. I simply recompiled Raylib with -DCUSTOMIZE_BUILD=ON, -DSUPPORT_FILEFORMAT_JPG=ON and -Draylib_USE_STATIC_LIBS=ON to enable it, then I copied the resulting libraylib.a into the appropriate Odin directory, and recompiled Odin as well.

@laytan
Copy link
Collaborator

laytan commented Sep 12, 2024

I don't think we should really deviate from the default Raylib build, like others said you can recompile with support and switch out the library.

An idea might be to better document (or provide scripts for) this process of recompilation.

@Kelimion
Copy link
Member

You could also petition Raylib upstream to have JPG included by default. I don't believe there's any patent encumbrance in JPG since the patent on arithmetic coding expired. And even while that patent was still alive, most JPG implementations (including Photoshop) went with Huffman coding instead of arithmetic coding because of that patent, so there was no reason to exclude JPG support that I can see.

@JulienLecoq
Copy link

JulienLecoq commented Sep 15, 2024

@paramita I just faced the same issue with SVG, it's very annoying from a user point of view. You're like, oh cool, I can just call LoadImageSvg() and you do it and it explode at you because in reality it's not there by default and you don't have any explanation of what to do to enable it.

@JulienLecoq
Copy link

JulienLecoq commented Sep 15, 2024

@Vonixxx Could you explain quickly how to recompile Raylib? I don't see much stuff in Odin/vendor/raylib. I don't have a strong background on compilation and so on.

@Vonixxx
Copy link

Vonixxx commented Sep 15, 2024

@Vonixxx Could you explain quickly how to recompile Raylib? I don't see much stuff in Odin/vendor/raylib. I don't have a strong background on compilation and so on.

I see you're on Windows, so I cannot assist with that. I use Linux.

You have to visit Raylib's own Github page for that anyhow, here's a link explaining how to build for Windows.

@JulienLecoq
Copy link

@Vonixxx Could you explain quickly how to recompile Raylib? I don't see much stuff in Odin/vendor/raylib. I don't have a strong background on compilation and so on.

I see you're on Windows, so I cannot assist with that. I use Linux.

You have to visit Raylib's own Github page for that anyhow, here's a link explaining how to build for Windows.

I'm on MacOS. Thanks, I'll look into that for MacOS.

@JulienLecoq
Copy link

JulienLecoq commented Sep 15, 2024

Mhh I'm a bit lost, where is raylib even installed when we install Odin? How can we find that per OS?

@flysand7
Copy link
Contributor

It's in the vendor folder inside the Odin repository

@JulienLecoq
Copy link

JulienLecoq commented Sep 19, 2024

I was asking for the code but I noticed that it does not install the code itself 👍🏻

@paramita I don't know if you succeeded to compile it with JPG enabled but if not, here is how I did it on MacOS on Apple Silicon architecture (idk the Windows equivalent):

  1. Install cmake with homebrew (requires homebrew to be installed): brew install cmake
  2. Clone raylib: git clone [email protected]:raysan5/raylib.git
  3. Go to the raylib directory: cd raylib
  4. Open the file CMakeLists.txt
  5. Add the line add_compile_definitions(SUPPORT_FILEFORMAT_JPG) just below the line include(CMakeOptions.txt)
  6. Save & quit the file and create a directory called build: mkdir build
  7. Go to the build directory: cd build
  8. Run the command: cmake ..
  9. Run the command: make
  10. Copy the file from raylib/build/raylib/libraylib.a to Odin/vendor/raylib/macos-arm64
  11. Load the file in your program and run your program, it should works 🙂

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

7 participants