Error loading textures with DevIL

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);
	
	//Bind
	ilBindImage(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 {
		printf("PERFECT!

");

	}

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:

[b]1290: could not open file[/b]

And sometimes, this one:

[b]1289: invalid parameter[/b]

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
ilInit();
// Initialize ILU
iluInit();
// Initialize ILUT with OpenGL support.
ilutRenderer(ILUT_OPENGL);

Thank you in advance for your help!

i dont know DevIL, but if you want to create textures by just calling a function, use SOIL:
http://www.lonesock.net/soil.html


/* load an image file directly as a new OpenGL texture */
GLuint tex_2d = SOIL_load_OGL_texture
	(
		"img.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
	);
	
/* check for an error during the load process */
if( 0 == tex_2d )
{
	printf( "SOIL loading error: '%s'
", 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
	(
		"terrain.tga",
		&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  );