View Full Version : Error loading textures with DevIL

07-29-2016, 06:29 AM
Hi guys,

I'm trying to load textures with DevIL and, but some reason, it's not working. Let me explain the problem.

First of all, I have an object with X meshes. I read it from "../assets/FerrariCalifornia/California/california.obj". In the same folder, I have a few .tga files that I need to load as textures. This is how I'm loading the files:

For every mesh of the object:

aiString texturePath;
const char *materialTexture;
unsigned char *textura;
ILstring texturita;
if (AI_SUCCESS == material->GetTexture(aiTextureType_DIFFUSE, 0, &texturePath))
materialTexture = texturePath.C_Str();
texturita = ((ILstring)materialTexture);

GLuint textureID;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);

//Image with DevIL
ilGenImages(1, &textureId);

//Load the image
ILboolean success = ilLoadImage(texturita);
ILenum Error;
while ((Error = ilGetError()) != IL_NO_ERROR) {
printf("%d: %s/n", Error, iluErrorString(Error));

//Check to see if everything went OK
if (!success) {
ilDeleteImages(1, &textureId);
else {


As you can see, I'm just trying to load the textures, nothing else. The problem is that it prints "PERFECT" during the first loop, but it's not working for the next loops. The following error appears:

1290: could not open file

And sometimes, this one:

1289: invalid parameter

Do you know why is this happening? I don't understand why it works for the first file and not for the other ones.

In case you are wondering, this is how I initialise DevIL:

/* ----- Initialise DevIL -----*/
// Initialize IL
// Initialize ILU
// Initialize ILUT with OpenGL support.

Thank you in advance for your help!

07-29-2016, 07:34 AM
i dont know DevIL, but if you want to create textures by just calling a function, use SOIL:

/* load an image file directly as a new OpenGL texture */
GLuint tex_2d = SOIL_load_OGL_texture

/* check for an error during the load process */
if( 0 == tex_2d )
printf( "SOIL loading error: '%s'\n", SOIL_last_result() );

or if you want to load a image without creating automatically a texture, use:

int width, height, channels;
unsigned char *data = SOIL_load_image
&width, &height, &channels,
SOIL_LOAD_L // set this to 4 for RGBA, 3 for RGB, ...

// create your texture here:

// and later release memory
SOIL_free_image_data( data );