alex2
February 26, 2011, 1:16pm
1
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.
alex2
February 26, 2011, 11:07pm
3
error 1291 - IL_INVALID_EXTENSION - but I have .bmp so it is good extension…
_arts
February 27, 2011, 1:38am
4
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.
alex2
February 27, 2011, 3:44am
5
alex2
February 27, 2011, 7:03am
6
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
alex2
March 1, 2011, 11:42am
7
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.
ughmoo
October 23, 2011, 1:52pm
9
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. : )