// DevIL sample. #include #include #include #include #include #undef USE_WCHAR_T int main(int argc, char *argv[]) { if (argc != 2) { printf("Usage:\n\thoge.exe IN.png\n"); return 0; } char *filename = argv[1]; ILuint img; int width, height; // DevIL init ilInit(); iluInit(); // generate image ID ilGenImages(1, &img); ilBindImage(img); #ifdef USE_WCHAR_T // char to wchar_t size_t newsize = strlen(filename) + 1; wchar_t *wcfilename = new wchar_t[newsize]; size_t convertedChars = 0; mbstowcs_s(&convertedChars, wcfilename, newsize, filename, _TRUNCATE); #endif ILboolean fg; if (1) { // not use ilLoadImage() ILubyte *lump; ILuint size; FILE *fp; fp = fopen(filename, "rb"); fseek(fp, 0, SEEK_END); size = ftell(fp); lump = (ILubyte *)malloc(size); fseek(fp, 0, SEEK_SET); fread(lump, 1, size, fp); fclose(fp); fg = ilLoadL(IL_PNG, lump, size); free(lump); } else { // use ilLoadImage() fg = ilLoadImage(filename); } if (fg) { // load success printf("Load : %s\n", filename); width = ilGetInteger(IL_IMAGE_WIDTH); height = ilGetInteger(IL_IMAGE_HEIGHT); printf("image size : %d x %d\n", width, height); if (ilGetInteger(IL_IMAGE_ORIGIN) != IL_ORIGIN_LOWER_LEFT) { iluFlipImage(); } } else { // load failure ILenum err = ilGetError(); std::cerr << iluErrorString(err) << std::endl; } ilDeleteImages(1, &img); #ifdef USE_WCHAR_T delete wcfilename; #endif return 0; }