This post describes how I managed to use the DevIL 1.7.8
image library in Curver to load and save images. Curver is a DirectX 9 application and I'm using the Express Edition of Visual C++ to build it. DevIL comes with a utility library to allow loading DirectX9 textures, but the library is built out of the SDK by default. So in order to use it, one has to download the DevIL source code and compile it himself, except that it comes with project files for the full version of MSVC which won't open in the Express Edition.
You can either ask somebody who has the full version of MSVC to download and compile DevIL for you with the right configuration flags, or you can do the following:
At this point you should be able to compile your DX9 program and run it. VC will complain that it is linking a locally defined version of ilutD3D9TexFromFile or something and may even give an error. Just build again and it should go away. This probably has to do with the use of ILAPI or ILAPIENTRY.
Finally, there is a little but somewhat serious bug in ilut_directx9.c, particularly in the MakeD3D9Compliant() function. The first variable declaration is "ILuint color". This should be "ILint color". Using an unsigned integer will cause the "perform alpha key on images if requested" test further below in the function to always pass, causing white pixels in your image to be converted to transparent, which is wrong, not to mention the unnecessary waisted processing. I'll send an e-mail to someone about it. Another thing to note is that this function will always scale the images to power-of-two sizes. This can be fixed by inserting a test for hardware support for non-power-of-two textures.
if( !CapsDX9Retrieved ) // Global boolean initialized to IL_FALSE.
IDirect3DDevice9_GetDeviceCaps( Device, &D3DCaps9 );
CapsDX9Retrieved = IL_TRUE;
if( (D3DCaps9.TextureCaps & D3DPTEXTURECAPS_POW2) ||
D3DCaps9.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL) )
// Images should have powers-of-2 dimensions.
One last thing I noticed is that using ilutD3D9TexFromFile() consumes a lot more memory than using ilutD3D9Texture for some unknown reason! Looking at the implementation of that function, I suspect the culprit is iBindImageTemp(), but I don't know. Here is how to load an image file to a DX9 texture without using ilutD3D9TexFromFile() then:
ILuint iImage = (ILuint)-1;
ilGenImages( 1, &iImage );
ilBindImage( iImage );
if( IL_TRUE == ilLoadImage( sFileName ) )
pTexture = ilutD3D9Texture( g_pD3DDevice );
width = (UINT)ilGetInteger( IL_IMAGE_WIDTH );
height = (UINT)ilGetInteger( IL_IMAGE_HEIGHT );
ilDeleteImages( 1, &iImage );
Hope this helps, and that I haven't missed anything. It was all more trial and error than anything else.