Dark Bit Factory & Gravity
PROGRAMMING => C / C++ /C# => Topic started by: Rbz on April 15, 2018
-
For those looking for a simple image loader, take a look at "stb image library" by Sean Barrett
https://github.com/nothings/stb
It's simple to use:
#define STB_IMAGE_IMPLEMENTATION
#define STBI_ONLY_PNG //You can request *only* certain decoders and suppress all other
#include "stb_image.h"
int x,y,n;
unsigned char *data = stbi_load(filename, &x, &y, &n, 0);
// ... process data if not NULL ...
// ... x = width, y = height, n = # 8-bit components per pixel ...
// ... replace '0' with '1'..'4' to force that many components per pixel
// ... but 'n' will always be the number that it would have been if you said 0
stbi_image_free(data)
// Standard parameters:
// int *x -- outputs image width in pixels
// int *y -- outputs image height in pixels
// int *channels_in_file -- outputs # of image components in image file
// int desired_channels -- if non-zero, # of image components requested in result
-
nice, i might use this as i use sdl, and that only works with bmp files
-
looks like it can do allot more than just images.
how do you actually compile and include it ? there are no .c files ! its all in the header files ? ive never seen something like that before
-
I also scratched my head on the first time I was using it, but in the end it is very simple.
Just all you need to do is to include this lines on your texture ".CPP" file:
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
It includes those functions on your source code and no other file or library is necessary, besides of course it uses the standard C runtime, needed for open file, memory allocation and etc.
Ps. I've only tested the image loader, but the other libs should be also simple to use, just take a look on the header file for example usage.