diff options
author | Chris Xiong <chirs241097@gmail.com> | 2019-06-15 13:19:46 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2019-06-15 13:19:46 +0800 |
commit | 2da6a4aec9a249417a9e4c0106ab6bec0489a36f (patch) | |
tree | 96b3d7bb38e01170fb59435a16ee4f7d2572d782 | |
parent | b859c1accbb2bf7b19f634346528458ccf11b6f1 (diff) | |
download | SMELT-2da6a4aec9a249417a9e4c0106ab6bec0489a36f.tar.xz |
Added DevIL as an option for image loader.
-rw-r--r-- | examples/makefile | 2 | ||||
-rw-r--r-- | smelt/glfw/gfx_glfw.cpp | 26 | ||||
-rw-r--r-- | 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<h;++i) + memcpy(px+w*(h-1-i),ilGetData()+w*i*sizeof(DWORD)/sizeof(ILubyte),w*sizeof(DWORD)); + } + ilDeleteImages(1,&iid); + ilShutDown(); +#endif + return px; } void SMELT_IMPL::bindTexture(glTexture *t) diff --git a/smelt/glfw/gfx_glfw_compat.cpp b/smelt/glfw/gfx_glfw_compat.cpp index 995f697..16ee500 100644 --- a/smelt/glfw/gfx_glfw_compat.cpp +++ b/smelt/glfw/gfx_glfw_compat.cpp @@ -582,6 +582,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()) @@ -589,7 +591,7 @@ DWORD* SMELT_IMPL::decodeImage(BYTE *data,const char *fn,DWORD size,int &w,int & w=img.GetWidth();h=img.GetHeight(); px=new DWORD[w*h]; BYTE *sptr=(BYTE*)px; - bool atunnel=img.AlphaIsValid(); + bool achannel=img.AlphaIsValid(); for(int i=0;i<h;++i) for(int j=0;j<w;++j) { @@ -597,9 +599,27 @@ DWORD* SMELT_IMPL::decodeImage(BYTE *data,const char *fn,DWORD size,int &w,int & *(sptr++)=rgb.rgbRed; *(sptr++)=rgb.rgbGreen; *(sptr++)=rgb.rgbBlue; - *(sptr++)=atunnel?rgb.rgbReserved:0xFF; + *(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<h;++i) + memcpy(px+w*(h-1-i),ilGetData()+w*i*sizeof(DWORD)/sizeof(ILubyte),w*sizeof(DWORD)); + } + ilDeleteImages(1,&iid); + ilShutDown(); +#endif + return px; } void SMELT_IMPL::bindTexture(glTexture *t) |