Results 1 to 10 of 10

Thread: lib3ds -> texture

  1. #1
    Senior Member Regular Contributor
    Join Date
    May 2004
    Location
    Renkum
    Posts
    193

    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:
    Code :
    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

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: lib3ds -> texture

    They hold the texels value.

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: lib3ds -> texture

    In fact what lib3ds calls texels are the texture coordinates.

    So, when you write this line:

    Code :
    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.

  4. #4
    Senior Member Regular Contributor
    Join Date
    May 2004
    Location
    Renkum
    Posts
    193

    Re: lib3ds -> texture

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

    So, when you write this line:

    Code :
    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.
    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

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: lib3ds -> texture

    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.

  6. #6
    Senior Member Regular Contributor
    Join Date
    May 2004
    Location
    Renkum
    Posts
    193

    Re: lib3ds -> texture

    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

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: lib3ds -> texture

    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.

  8. #8
    Senior Member Regular Contributor
    Join Date
    May 2004
    Location
    Renkum
    Posts
    193

    Re: lib3ds -> texture

    Ok, thanx.
    Hylke

  9. #9
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: lib3ds -> texture

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

    Code :
    ...
    for( t=0; t<mesh->faces; ++t){
       Lib3dsFace *f=&amp;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

  10. #10
    Senior Member Regular Contributor
    Join Date
    May 2004
    Location
    Renkum
    Posts
    193

    Re: lib3ds -> texture

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

Similar Threads

  1. lib3ds show 3d object with texture
    By revaldo666 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 07-28-2012, 04:09 AM
  2. how to use lib3ds
    By deepha in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 11-11-2005, 02:06 AM
  3. lib3ds
    By deepha in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 11-10-2005, 02:38 AM
  4. Lib3DS + Texture ?
    By Leyder Dylan in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 10-15-2001, 07:27 AM
  5. texture mapping using lib3ds
    By indriyat in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 09-05-2001, 01:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean