lib3ds -> texture

Hello,
I’ve written a class that loads and renders a 3ds model using lib3ds.
But for some dark reason it crashes when it’s trying to generate mipmap levels using gluBuild2DMipmaps.
I’m thinking the problem is that the texels that I pass to gluBuild2DMipmaps are not texels(in other words, I don’t have the right variable that is holding the texels).
Here’s the function:

void Model::ApplyTexture(Lib3dsMesh *mesh)
{
	if(mesh->texels) //if we have texels
	{
		GLuint tmpIndex; // temporary index to old the place of our texture
		glGenTextures(1, &tmpIndex); // allocate memory for one texture
		textureIndices.push_back(tmpIndex); // add the index of our newly created texture to textureIndices
		glBindTexture(GL_TEXTURE_2D, tmpIndex); // use our newest texture
		gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, (int)pow(mesh->texels, 0.5) /*square root of pixels*/, (int)pow(mesh->texels, 0.5), GL_RGBA, GL_FLOAT, mesh->texelL); // genereate MipMap levels for our texture 
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // give the best result for texture magnification
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //give the best result for texture minification
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); // don't repeat texture 
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); // don't repeat texture
	}
}

So I’m thinking that mesh->texelL doesn’t hold the texels(because when I printed th contents I got this output: 0x81ae3d8(although the width is only 5 pixels, the output should be longer)).
Could anyone tell me which variable does contain the texels of the mesh?
Thanx in advance,
Hylke

They hold the texels value.

In fact what lib3ds calls texels are the texture coordinates.

So, when you write this line:

gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, (int)pow(mesh->texels, 0.5),(int)pow(mesh->texels, 0.5), GL_RGBA, GL_FLOAT, mesh->texelL);

you put the texture coordinates into the texture which is wrong. Textures expect rgb values for each pixel of the texture. That’s not handled with lib3ds.

Originally posted by jide:
[b]In fact what lib3ds calls texels are the texture coordinates.

So, when you write this line:

gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, (int)pow(mesh->texels, 0.5),(int)pow(mesh->texels, 0.5), GL_RGBA, GL_FLOAT, mesh->texelL);

you put the texture coordinates into the texture which is wrong. Textures expect rgb values for each pixel of the texture. That’s not handled with lib3ds.[/b]
I thought that they were the pixels(or texels called in my OpenGL red book).
But to use texturing I manually need to load the files?
Does the variable name in the structure Lib3dsMesh holds the name of the file of the texture?
Thanx in advance,
Hylke

You’re right: a texel is generally a texture pixel. I don’t know why lib3ds made this. Anyway.

You effectively need to load ‘manually’ the image file.

For knowing the file name the best thing is to dump the file (threw lib3ds_dump) so that you can see ‘what matches what’. If I remember well it should be called texture1_map, texture2_map, reflection_map and so on. They are certainly structures holding the file name among others.

Thank you for your reply.
Could you be more specific about what you mean with a ‘dump’?
And the function ‘lib3ds_dump()’ does not exist in the current version of lib3ds(that is, 1.2.0).
And how do I gather information from a dump?
Thanx in advance,
Hylke

lib3ds (at least my version: 1.1) provides examples, from them, there is the lib3ds_dump binary example. Execute it with giving a 3ds file as argument. It will dump all the info of the file on screen (with a human readable format) so that you can see what you have.

Ok, thanx.
Hylke

Okay, I had time to look at my code, so here is how I do that:

...
for( t=0; t<mesh->faces; ++t){
   Lib3dsFace *f=&mesh->faceL[t];
   
   if( f->material[0])
      mat=lib3ds_file_material_by_name( file, f->material);				
   else
      continue;

   if( strlen( mat->texture1_map.name)>0){
      meshes.tex_rot[meshes.m_count]= mat->texture1_map.rotation;
      cur_mesh->tri[t].TT.i= textures.Create( mat->texture1_map.name, TEXTURE_DIRECTORY);
   }
   ...

   if( mesh->texels>0){
      meshes.texels[k]= offset[0]+scale[0]*mesh->texelL[f->points[i]][0];
      meshes.texels[k+1]= offset[1]+scale[1]*mesh->texelL[f->points[i]][1];
   }
   ...
}
...

This is obviously not all the code but that must help you :wink:

I already have a code something similar to that, but thanx anyway.
Hylke