Texturing about the 3ds file loading with OpenGL

Started by
2 comments, last by hjfyyy 13 years, 6 months ago
Hi, everyone.
This is a noble problem. I use OpenGL to loader 3ds file which is a helicopter model. And the texture images are also loading correctly. But some textures are displayed normally, some are disappeared. So is there any extra information about the relation between a face and its material? Any ideas will be appreciated. Hope to make myself clear.
Here is my rendering code:
tMaterial *mat;t3DObject *obj;int	  *index;	for (int nOfObj=0; nOfObj<m_pModel->numOfObjects; nOfObj++){	obj = &m_pModel->pObject[nOfObj];	for (int nOfFace=0; nOfFace<obj->numOfFaces; nOfFace++)	{		index = obj->pFaces[nOfFace].vertIndex;		mat  = &m_pModel->pMaterials[obj->pFaces[nOfFace].matID];		if (mat->isTexMat)	// If the corresponding face has texture                  {		     glEnable(GL_TEXTURE_2D);		     glBindTexture(GL_TEXTURE_2D, mat->texureId);				     glColor3ub(mat->color[0], mat->color[1], mat->color[2]);		     // Render the triangles		      glBegin(GL_TRIANGLES);		     glTexCoord2f(obj->pTexVerts[index[0]].x,obj->pTexVerts[index[0]].y);		     glNormal3f(obj->pNormals[index[0]].x,obj->pNormals[index[0]].y,obj->pNormals[index[0]].z);		     glVertex3f(obj->pVerts[index[0]].x, obj->pVerts[index[0]].y, obj->pVerts[index[0]].z);		     glTexCoord2f(obj->pTexVerts[index[1]].x,obj->pTexVerts[index[1]].y);		     glNormal3f(obj->pNormals[index[1]].x,obj->pNormals[index[1]].y,obj->pNormals[index[1]].z);		     glVertex3f(obj->pVerts[index[1]].x, obj->pVerts[index[1]].y, obj->pVerts[index[1]].z);		     glTexCoord2f(obj->pTexVerts[index[2]].x,obj->pTexVerts[index[2]].y);		     glNormal3f(obj->pNormals[index[2]].x,obj->pNormals[index[2]].y,obj->pNormals[index[2]].z);		     glVertex3f(obj->pVerts[index[2]].x, obj->pVerts[index[2]].y, obj->pVerts[index[2]].z);		     glEnd();		}		else    // Has no texture		{		     glDisable(GL_TEXTURE_2D);		     glColor3ub(mat->color[0], mat->color[1], mat->color[2]);		     glBegin(GL_TRIANGLES);		     glNormal3f(obj->pNormals[index[0]].x,obj->pNormals[index[0]].y,obj->pNormals[index[0]].z);		     glVertex3f(obj->pVerts[index[0]].x, obj->pVerts[index[0]].y, obj->pVerts[index[0]].z);		     glNormal3f(obj->pNormals[index[1]].x,obj->pNormals[index[1]].y,obj->pNormals[index[1]].z);		     glVertex3f(obj->pVerts[index[1]].x, obj->pVerts[index[1]].y, obj->pVerts[index[1]].z);		     glNormal3f(obj->pNormals[index[2]].x,obj->pNormals[index[2]].y,obj->pNormals[index[2]].z);		     glVertex3f(obj->pVerts[index[2]].x, obj->pVerts[index[2]].y, obj->pVerts[index[2]].z);		     glEnd();                }	}}

The pointer m_pModel is the helicopter model loaded from a .3ds file.
Advertisement
I searched google, and found that there was different versions of codes loading 3ds file, but none worked correctly. Their differents mainly lay on the material chunk. One links a material with an object, and another links a material with a face of an object. Any way, they all can't make the all of textures display normally. Any suggestions?
Best Regards.
I tried Lib3ds, but still the problem hasn't been solved yet. Anyone who has dealt with such problems before, please give me a way. Thanks.
Best wishes
I debugged the detail information of the 3ds object returned by Lib3ds loading functions, and found that the faces whose textures hadn't been displayed normally had a bump_map member which was a file name of a image file, so I searched bump mapping in OpenGL , knowing there existed a technique named Bump mapping. Then I applied this technique, but unfortunately, still the texture has not shown. Any one know other causes?
Best Regards
Hu Jingfei

This topic is closed to new replies.

Advertisement