I can't load image using devil library why ?

Why I can’t load image using devil library ?


        ilInit(); /* Initialization of DevIL */
	ilGenImages(1, &texid); /* Generation of one image name */
	ilBindImage(texid); /* Binding of image name */
	success = ilLoadImage(TEXT("C:/Users/TEST/Desktop/nehe.bmp")); /* Loading of image "image.jpg" */
	if (success == IL_FALSE) 
	{
			ILenum error;
			error = ilGetError();
			MessageBox(NULL,TEXT("error"),TEXT("error"),MB_OK | MB_ICONINFORMATION);
	}

It gives me messagebox with text ‘error’ why ?

It gives me messagebox with text ‘error’ why ?

It gives you the text ‘error’ because that’s what you had it print when an error happens. You need to look at the contents of the enumerator to know what error you actually got.

error 1291 - IL_INVALID_EXTENSION - but I have .bmp so it is good extension…

The image format is not bmp, as said by the error number.

cf: http://www.shatters.net/~t00fri/DevIL_Docs/IL/IL_INVALID_EXTENSION.html

As I can remember devil has function to let devil discovers the file type.

This is BMP !

I think this library has bug - many people have the same problem:

http://sourceforge.net/projects/openil/forums/forum/13560/topic/4045391

http://sourceforge.net/tracker/?func=detail&aid=2990437&group_id=4470&atid=204470

http://www.gamedev.net/topic/586783-need-help-using-soil/

Now I am using SDL library. This library works but images are upside-down lol ! For example point (0, 0) is upper left, not lower left - I don’t know what I should do - should I accept this SDL behaviour and use SDL coordinates ?

Here are relative topics with this issue:
http://www.gamedev.net/topic/188170-opengl-texture-mapping-question-sdl/

http://bhsphd.spaces.live.com/blog/cns!1844003DFD14BA7D!312.entry

I have found solution for invert image in SDL: http://www.gribblegames.com/articles/game_programming/sdlgl/invert_sdl_surfaces.html

So the solution is to invert image:


int invert_image(int pitch, int height, void* image_pixels)
{
   int index;
   void* temp_row;
   int height_div_2;

   temp_row = (void *)malloc(pitch);
   if(NULL == temp_row)
   {
      SDL_SetError("Not enough memory for image inversion");
      return -1;
   }
   //if height is odd, don't need to swap middle row
   height_div_2 = (int) (height * .5);
   for(index = 0; index < height_div_2; index++)    {
      //uses string.h
      memcpy((Uint8 *)temp_row,
         (Uint8 *)(image_pixels) +
         pitch * index,
         pitch);

      memcpy(
         (Uint8 *)(image_pixels) +
         pitch * index,
         (Uint8 *)(image_pixels) +
         pitch * (height - index-1),
         pitch);
      memcpy(
         (Uint8 *)(image_pixels) +
         pitch * (height - index-1),
         temp_row,
         pitch);
   }
   free(temp_row);
   return 0;
}

//This is the function you want to call!
int SDL_InvertSurface(SDL_Surface* image)
{
   if(NULL == image)
   {
      SDL_SetError("Surface is NULL");
      return -1;
   }
   return( invert_image(image->pitch, image->h,
         image->pixels) );
} 

example usage:


SDL_Surface* surface;
surface = IMG_Load(filename)
SDL_InvertSurface(surface);
//.........

BMP files are allowed to be inverted and this is signified by a negative value for height in the header; it’s a legal part of the format.

I really really do recommend using a different file format, such as TGA.

Sorry to bump oldish thread but it was the top one on google for the error.
Wanted to say the guy was right, there is a bug in DevIL, Im using the 2008 version of DevIL now (1.7.3) and it’s working fine. : )