Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Cross Platform Image Loader for OpenGL

Tags:

image

opengl

I have tried everything from SDL to DevIL, and they have all failed for various reasons.

SDL segfaults for various reasons, and DevIL is having some weird problem where even after i include IL/ilut.h and linking everything, and including the other headers, it is not defining the functions i need to load images into opengl textures (something about USE_OPEN_GL not being defined). I am asking for any other lib out there for loading bitmaps or png's into a format i can easily convert to opengl, or a solution to the devil problem.

thanks

like image 532
jimi hendrix Avatar asked Jul 15 '09 01:07

jimi hendrix


4 Answers

Both libpng and libjpeg can be rather daunting to build & use -- no wonder there are all sorts of wrapper libraries for both.

A very simple and minimal no-nonsense loader for jpg/png (and some other stuff aswell) without dependencies in a single C file is Sean Barrett's stb_image.c, if you just want to load some image files it adds absolutely minimal overhead to your program and is straightforward to use:

http://nothings.org/stb_image.c

like image 160
Ákos Avatar answered Oct 28 '22 07:10

Ákos


As Adam suggests, I would also recommend to use libpng and libjpeg. You are not specifying if you write in C or C++, but if in C++, then I'd suggest to take a look at two handy thin wrappers on the both libraries: pngxx and jpegxx

like image 34
mloskot Avatar answered Oct 28 '22 07:10

mloskot


LodePNG is a highly compact PNG Loader with no dependencies.

Comment on your experience with DevIL - it works flawlessly for me and many others. Why not try again to resolve your build problems? - shouldn't be too hard)

like image 20
Alexander Gessler Avatar answered Oct 28 '22 05:10

Alexander Gessler


You can also try FreeImage library. It supports loading different image types and is functionally similar to DevIL, may work out of the box for you.

And about your problem with DevIL, you do not have to build ilu or ilut libraries to make DevIL functional. I would recommend you manage the OpenGL texture objects yourself, including uploading image data to OpenGL side.

like image 39
AdilYalcin Avatar answered Oct 28 '22 06:10

AdilYalcin