3ds Model--Improve TGA Texture Display

As you know, there are several models that can't display texture maps, and texture file names have been changed, almost all of them are TGA files.Why should anyone change it?Maybe CLoad3DS::BuildTexture does not support these TGAs.Now solve the problem.
TGATexture.h and TGATexture.cpp can display TGA files in the blog "OpenGL" Detailed description of common TGA image formats for game programming and implementation of loading texture programming". Take them for testing:

This "Medium Tree.tga" can be displayed, but some can not be displayed. It can only be used in conjunction with each other.

Simple modification for easy use

Add a function to TGATexture.cpp:

bool LoadTGATexture(char *szPathName, GLuint &texid)         // Intercept TGA Texture
{
	TextureImage texture[1]; 
	bool b=LoadTGA(&texture[0],szPathName);//Invoke the original
	texid=texture[0].texID;
	return b;

}
Add at BuildTexture in CLoad3DS::ReadObjectMaterial:

int tmp=BuildTexture(pModel->pMaterials[i].strFile, pModel->texture[pObject->materialID]);
if( tmp==true){
	// Set the texture mapping flag of the object
	pObject->bHasTexture = true;
}
else{//If unsuccessful, TGA, try again

	string s=string(pModel->pMaterials[i].strFile);
	size_t tmp,tmp1,tmp2;
	tmp1=s.rfind(".tga");tmp2=s.rfind(".TGA");//Is it a TGA file
	if ((tmp1==s.length()-4)||(tmp2==s.length()-4)){
		char  szPath[MAX_PATH+1];
		GetCurrentDirectory(MAX_PATH, szPath);              // Get the project directory
		strcat(szPath, PICPATH);                      // Add "\Data\\pic\pic\" to the working directory
		strcat(szPath, s.data());                    // Add file name after

		tmp=LoadTGATexture(szPath, pModel->texture[pObject->materialID]);//Loading TGA Texture
		if( tmp==true){
			// Set the texture mapping flag of the object
			pObject->bHasTexture = true;
	
		}
		//else{
		//char strMessage[100];
		//sprintf(strMessage, "file name : %s!", pModel->pMaterials[i].strFile);
		//printf( "%s\n" , strMessage );
		//MessageBox(NULL, strMessage, "Error", MB_OK);
		//}
	}
}
Design sketch:

The latter is no effect.



Tags: Programming

Posted on Thu, 23 Apr 2020 09:10:17 -0700 by plutarck