From 2da6a4aec9a249417a9e4c0106ab6bec0489a36f Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sat, 15 Jun 2019 13:19:46 +0800 Subject: Added DevIL as an option for image loader. --- examples/makefile | 2 +- smelt/glfw/gfx_glfw.cpp | 26 ++++++++++++++++++++++++++ smelt/glfw/gfx_glfw_compat.cpp | 24 ++++++++++++++++++++++-- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/examples/makefile b/examples/makefile index c927ae7..48b4891 100644 --- a/examples/makefile +++ b/examples/makefile @@ -1,7 +1,7 @@ CC= g++ CXXFLAGS= -I/usr/include/freetype2 -I../include -D_LINUX -g LINK= -lSDL2 -lvorbis -lvorbisfile -lopenal -ljpeg -lpng -lfreetype -lz -lsmeltext -lsmelt -lCxImage -LINK_GLFW= -lglfw -lGLEW -lGL -lvorbis -lvorbisfile -lopenal -ljpeg -lpng -lfreetype -lz -lsmeltext -lsmelt -lCxImage +LINK_GLFW= -lglfw -lGLEW -lGL -lvorbis -lvorbisfile -lopenal -ljpeg -lpng -lfreetype -lz -lsmeltext -lsmelt -lIL -lILU LINK_FOLDER= -L../smelt/sdl -L../extensions LINK_GLFW_FOLDER= -L../smelt/glfw -L../extensions diff --git a/smelt/glfw/gfx_glfw.cpp b/smelt/glfw/gfx_glfw.cpp index c545073..aa5f4bd 100644 --- a/smelt/glfw/gfx_glfw.cpp +++ b/smelt/glfw/gfx_glfw.cpp @@ -9,7 +9,13 @@ * */ #include "smelt_internal.hpp" + +#ifdef USE_CXIMAGE #include "CxImage/ximage.h" +#else +#include "IL/il.h" +#endif + #define dbg printf("%d: 0x%X\n",__LINE__,glGetError()) #ifndef USE_OPENGL_COMPATIBILITY_PROFILE #include "smmath_priv.hpp" @@ -575,6 +581,8 @@ DWORD* SMELT_IMPL::decodeImage(BYTE *data,const char *fn,DWORD size,int &w,int & } return px; } + +#ifdef USE_CXIMAGE CxImage img; img.Decode(data,size,CXIMAGE_FORMAT_UNKNOWN); if(img.IsValid()) @@ -593,6 +601,24 @@ DWORD* SMELT_IMPL::decodeImage(BYTE *data,const char *fn,DWORD size,int &w,int & *(sptr++)=achannel?rgb.rgbReserved:0xFF; } } +#else + ilInit(); + ILuint iid; + ilGenImages(1,&iid); + if(ilLoadL(IL_TYPE_UNKNOWN,data,size)) + { + w=ilGetInteger(IL_IMAGE_WIDTH); + h=ilGetInteger(IL_IMAGE_HEIGHT); + if(ilGetInteger(IL_IMAGE_FORMAT)!=IL_UNSIGNED_INT||ilGetInteger(IL_IMAGE_TYPE)!=IL_RGBA) + ilConvertImage(IL_UNSIGNED_INT,IL_RGBA); + px=new DWORD[w*h]; + for(int i=0;i