problem of mapping

Hi,
I try to map a mesh but the result is stange it isn’t mapped correctly…
glGetError give me the GL_INVALID_ENUM error, i don’t know what it is :frowning:
i read coordinates in a .3ds file.
the texture which i map has some black parts(which mustn’t be mapped) and we see these parts on the model :-/
are there conditions about the texture to map with opengl ?(except that i must be a power of two texture)
Can you help me ?

here is some code :

 glGenTextures (myLoader->getCounterObj()+1, texname);	

	int i ;
	for(i=0 ; i <=/*1*/ myLoader->getCounterObj() ; i++)
	{
					SDL_Surface *texture=IMG_Load(/*"bois.bmp""eyeball.tif"*/myLoader->myObjects[i].textureNames/*"wood_b.TGA""herbe.bmp"*/);
			cout<<"texture "<<texture<<" nomTex "<<myLoader->myObjects[i].textureNames<<endl ;//gérer le compteur d'objets dans 0xa300
			
			glBindTexture (GL_TEXTURE_2D, texname[i]) ;
	
			glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
			glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
			glTexParameteri (GL_TEXTURE_2D,	GL_TEXTURE_MAG_FILTER,GL_LINEAR);
			glTexParameteri (GL_TEXTURE_2D,	GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	
			glTexImage2D(GL_TEXTURE_2D, 0, 3, texture->w, texture->h,
					0, GL_RGB, GL_UNSIGNED_BYTE, texture->pixels);
	
		
	}
	glEnable(GL_TEXTURE_2D) ; 

It seems it’s more your texture coordinates that aren’t well. Did you ensure they’re all clamped between 0 and 1 ?
I haven’t seen your work on how you assign texture coordinates, but what I can say is that 3ds uses offsets and scaling for them.

You should also have a deeper look on how to create textures. Normally you enable texturing before doing anything on them, but you do it at last.

Do you know when you have the gl error ?

i have this error just at the end of the block that i have put above. This block is called after the execution of the loader wihich read coordinates. coordinates are well between 0 and 1.I enable texturing there without really good reason but they do the same in the red book.

can you tell me more about “3ds uses offsets and scaling for them” ? what have i forgotten ?

where do you create those texnames ?
the ones you use for binding

I somewhat miss the “glGenTextures” call

Originally posted by CrazyButcher:
[b]where do you create those texnames ?
the ones you use for binding

I somewhat miss the “glGenTextures” call[/b]
glGenTexture is at the first line of the code that i have posted and texname is a global variable.

I found your problem I think :slight_smile:

Just replace:

glTexImage2D(GL_TEXTURE_2D, 0, 3, texture->w, texture->h, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->pixels);

by

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture->w, texture->h, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->pixels);

3 might be the vaule of GL_RGB, but you shouldn’t do that like that. Also enable texturing before doing anything on them as I said.

About offsets and scalings. I think they are stored inside the texture (in 3DS files). An offset stipples when the texture starts and the scaling how it is scaled toward its dimensions. You’ll need to take care of them if you expect your models to be fully and well textured. Sometimes, your texture coordinates won’t be clamped between 0 and 1, but that’s the way of offsets and scalings. Just apply an easy algorithm to your texture coordinates for that (T = o + t * s) with T the new tex coords, o the offset, s the scaling and t the not transformed tex coords.

Hope that helps.

i have just found this :
"* 4170 Standard mapping

First 2 bytes: type of mapping
0 = plannar or specific (in this case, like mapping from the lofter,
the information of this chunk is irrelevant)
1 = cylindrical
2 = spherical

then come 21 floats that describe the mapping."

do you think that these 21 floats can help in my case ?
Otherwise i’ll maybe say something of stupid but do you think the transformation matrix can help me ?

Where did you took those info from ?

When I load a 3ds file from lib3ds, each node has textures (texture1,texture2,texture_reflection and so on). For each of those, there are values for offsets and scalings.

I cannot say more.

i have found something about what you told me : it is chunks with others about materials, but with the file which works bad there are not these chunks (they are optionals)there is just a “map option” chunk which i don’t know how read.
i’ll try to find another file to check.

PS: the info of the previous post come from a file which i downloaded from gametutorials.com when it was free but there are other sites like this :
in french : http://mustapha.bismi.free.fr/frame.html
in english :
http://www.spacesimulator.net/tut4_3dsloader.html
http://www.morrowland.com/apron/article/general/autodesk_3ds/index.php