TexManager.cpp
上传用户:hkb425
上传日期:2007-06-16
资源大小:34191k
文件大小:12k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. // TexManager.cpp: implementation of the CTexManager class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "TexManager.h"
  6. #include "texture.h"
  7. #include "gamesetting.h"
  8. #include "imgText.h"
  9. //////////////////////////////////////////////////////////////////////
  10. // Construction/Destruction
  11. //////////////////////////////////////////////////////////////////////
  12. unsigned int *CTexManager::m_texList=NULL;
  13. int           CTexManager::m_numUser=0;
  14. CTexManager::CTexManager()
  15. {
  16. if(m_numUser==0)
  17. {
  18. m_texList=new unsigned int [MAX_TEXTURE_NUM];
  19. for(int i=0;i<MAX_TEXTURE_NUM;i++)
  20. m_texList[i]=0;
  21. }
  22. m_numUser++;
  23. }
  24. CTexManager::~CTexManager()
  25. {
  26. m_numUser--;
  27. if(m_numUser==0 && m_texList!=NULL)
  28. {
  29. delete [] m_texList;
  30. }
  31. }
  32. //////////////////////////////////////////////////
  33. bool CTexManager::CreateMenuResource()
  34. {
  35.     CTexture cTex;
  36. int  error=0;
  37. //////////// imgtext
  38. if(!cTex.MakeTextureBind("texture/myfont.BMP",&m_texList[TEX_IMAGE_TEXT],0,0))error++;
  39. CImgText::m_texFont=m_texList[TEX_IMAGE_TEXT];
  40.     //////////// bkg
  41. if(!cTex.MakeTextureBind("texture/bkg.BMP",&m_texList[TEX_MENU_BKG],0,0))error++;
  42. ///////////// cursor
  43. if(!cTex.MakeAlphaTextureBind("texture/cur16.BMP","texture/cur16Alpha.bmp",&m_texList[TEX_MENU_CURSOR]))error++;
  44. ////////////My Photos
  45. if(!cTex.MakeTextureBind("model/soldier/hpts/a.hpt",&m_texList[TEX_MY_PHOTO_0],1,0))error++;
  46. if(!cTex.MakeTextureBind("model/soldier/hpts/b.hpt",&m_texList[TEX_MY_PHOTO_1],1,0))error++;
  47. if(!cTex.MakeTextureBind("model/soldier/hpts/c.hpt",&m_texList[TEX_MY_PHOTO_2],1,0))error++;
  48. ////////////Hero Photos
  49. if(!cTex.MakeTextureBind("model/soldier/hpts/hero0.hpt",&m_texList[TEX_HERO_PHOTO_0],1,0))error++;
  50. if(!cTex.MakeTextureBind("model/soldier/hpts/hero1.hpt",&m_texList[TEX_HERO_PHOTO_1],1,0))error++;
  51. if(!cTex.MakeTextureBind("model/soldier/hpts/hero2.hpt",&m_texList[TEX_HERO_PHOTO_2],1,0))error++;
  52. if(!cTex.MakeTextureBind("model/soldier/hpts/hero3.hpt",&m_texList[TEX_HERO_PHOTO_3],1,0))error++;
  53. ////////////Sketch
  54. if(!cTex.MakeTextureBind("texture/sketch/sketch00.bmp",&m_texList[TEX_MISSION_SKETCH_0],1,0))error++;
  55. if(!cTex.MakeTextureBind("texture/sketch/sketch01.bmp",&m_texList[TEX_MISSION_SKETCH_1],1,0))error++;
  56. if(!cTex.MakeTextureBind("texture/sketch/sketch02.bmp",&m_texList[TEX_MISSION_SKETCH_2],1,0))error++;
  57. if(!cTex.MakeTextureBind("texture/sketch/sketch03.bmp",&m_texList[TEX_MISSION_SKETCH_3],1,0))error++;
  58. if(!cTex.MakeTextureBind("texture/sketch/sketch04.bmp",&m_texList[TEX_MISSION_SKETCH_4],1,0))error++;
  59. if(!cTex.MakeTextureBind("texture/sketch/sketch05.bmp",&m_texList[TEX_MISSION_SKETCH_5],1,0))error++;
  60. /////doc
  61. if(!cTex.MakeTextureBind("script/doc.bmp",&m_texList[TEX_DOCUMENT],1,0))error++;
  62. if(error==0)return true;
  63. else return false;
  64. }
  65. void  CTexManager::DeleteMenuResource()
  66. {
  67. glDeleteTextures(1,&m_texList[TEX_IMAGE_TEXT]);
  68. glDeleteTextures(1,&m_texList[TEX_MENU_BKG]);
  69. glDeleteTextures(1,&m_texList[TEX_MENU_CURSOR]);
  70. glDeleteTextures(1,&m_texList[TEX_MY_PHOTO_0]);
  71. glDeleteTextures(1,&m_texList[TEX_MY_PHOTO_1]);
  72. glDeleteTextures(1,&m_texList[TEX_MY_PHOTO_2]);
  73. glDeleteTextures(1,&m_texList[TEX_HERO_PHOTO_0]);
  74. glDeleteTextures(1,&m_texList[TEX_HERO_PHOTO_1]);
  75. glDeleteTextures(1,&m_texList[TEX_HERO_PHOTO_2]);
  76. glDeleteTextures(1,&m_texList[TEX_HERO_PHOTO_3]);
  77. glDeleteTextures(1,&m_texList[TEX_MISSION_SKETCH_0]);
  78. glDeleteTextures(1,&m_texList[TEX_MISSION_SKETCH_1]);
  79. glDeleteTextures(1,&m_texList[TEX_MISSION_SKETCH_2]);
  80. glDeleteTextures(1,&m_texList[TEX_MISSION_SKETCH_3]);
  81. glDeleteTextures(1,&m_texList[TEX_MISSION_SKETCH_4]);
  82. glDeleteTextures(1,&m_texList[TEX_MISSION_SKETCH_5]);
  83. glDeleteTextures(1,&m_texList[TEX_DOCUMENT]);
  84. }
  85. ////////////////////////////////////////////////////
  86. bool CTexManager::CreateMissionResource()
  87. {
  88.     CTexture cTex;
  89. int  error=0;
  90. char filename[96];
  91. int  dirlen;
  92. ///////////////////image text
  93.   if(!cTex.MakeTextureBind("texture/myfont.BMP",&m_texList[TEX_IMAGE_TEXT],0,0))error++;
  94. CImgText::m_texFont=m_texList[TEX_IMAGE_TEXT]; 
  95. //////////sky
  96. strcpy(filename,CGameSetting::m_strSkyDir);
  97.     dirlen=strlen(filename);
  98.     strcpy(filename+dirlen,"skyb0.bmp");
  99. if(!cTex.MakeTextureBind(filename,&m_texList[TEX_SKY_0],1,0))error++;
  100.     strcpy(filename+dirlen,"skyb1.bmp");
  101. if(!cTex.MakeTextureBind(filename,&m_texList[TEX_SKY_1],1,0))error++;
  102.     strcpy(filename+dirlen,"skyb2.bmp");
  103. if(!cTex.MakeTextureBind(filename,&m_texList[TEX_SKY_2],1,0))error++;
  104.     strcpy(filename+dirlen,"skyb3.bmp");
  105. if(!cTex.MakeTextureBind(filename,&m_texList[TEX_SKY_3],1,0))error++;
  106.     strcpy(filename+dirlen,"skyb4.bmp");
  107. if(!cTex.MakeTextureBind(filename,&m_texList[TEX_SKY_4],1,0))error++;
  108. if(CGameSetting::m_bLensFlare)
  109. {
  110. //// LensFlare
  111. if(!cTex.MakeAlphaTextureBind("flare/flare0.bmp",&m_texList[TEX_LENSFLARE_0]))error++;
  112. if(!cTex.MakeAlphaTextureBind("flare/flare1.bmp",&m_texList[TEX_LENSFLARE_1]))error++;
  113. if(!cTex.MakeAlphaTextureBind("flare/flare2.bmp",&m_texList[TEX_LENSFLARE_2]))error++;
  114. if(!cTex.MakeAlphaTextureBind("flare/flare3.bmp",&m_texList[TEX_LENSFLARE_3]))error++;
  115. if(!cTex.MakeAlphaTextureBind("flare/flare4.bmp",&m_texList[TEX_LENSFLARE_4]))error++;
  116. if(!cTex.MakeAlphaTextureBind("flare/flare5.bmp",&m_texList[TEX_LENSFLARE_5]))error++;
  117. if(!cTex.MakeAlphaTextureBind("flare/flare6.bmp",&m_texList[TEX_LENSFLARE_6]))error++;
  118. }
  119. //////////terrain
  120. strcpy(filename,CGameSetting::m_strTerrainSkinDir);
  121.     dirlen=strlen(filename);
  122.     
  123.     strcpy(filename+dirlen,"a1.bmp");
  124. if(!cTex.MakeTextureBind(filename,&m_texList[TEX_TERRAIN_A1]))error++;
  125.     strcpy(filename+dirlen,"a2.bmp");
  126. if(!cTex.MakeTextureBind(filename,&m_texList[TEX_TERRAIN_A2]))error++;
  127.     strcpy(filename+dirlen,"a3.bmp");
  128. if(!cTex.MakeTextureBind(filename,&m_texList[TEX_TERRAIN_A3]))error++;
  129.     strcpy(filename+dirlen,"b1.bmp");
  130. if(!cTex.MakeTextureBind(filename,&m_texList[TEX_TERRAIN_B1]))error++;
  131.     strcpy(filename+dirlen,"b2.bmp");
  132. if(!cTex.MakeTextureBind(filename,&m_texList[TEX_TERRAIN_B2]))error++;
  133.     strcpy(filename+dirlen,"b3.bmp");
  134. if(!cTex.MakeTextureBind(filename,&m_texList[TEX_TERRAIN_B3]))error++;
  135.     strcpy(filename+dirlen,"TerSkin1.skn");
  136. if(!cTex.MakeSkinTextureBind(filename,&m_texList[TEX_TERRAIN_SKN1]))error++;
  137.     strcpy(filename+dirlen,"TerSkin2.skn");
  138. if(!cTex.MakeSkinTextureBind(filename,&m_texList[TEX_TERRAIN_SKN2]))error++;
  139.     strcpy(filename+dirlen,"TerSkin3.skn");
  140. if(!cTex.MakeSkinTextureBind(filename,&m_texList[TEX_TERRAIN_SKN3]))error++;
  141.     strcpy(filename+dirlen,"TerSkin4.skn");
  142. if(!cTex.MakeSkinTextureBind(filename,&m_texList[TEX_TERRAIN_SKN4]))error++;
  143.    
  144. ///////////detail texture
  145. // if(!cTex.MakeTextureBind("terrains/detail2.bmp",&m_texList[TEX_TERRAIN_DETAIL_0]))error++;
  146. ///////////////////Plants
  147. char alphaname[96];
  148. strcpy(filename, CGameSetting::m_strPlantsDir);
  149. strcpy(alphaname,CGameSetting::m_strPlantsDir);
  150.     dirlen=strlen(filename);
  151.    //tree body
  152. if(!cTex.MakeTextureBind("plants/treebody2.bmp",&m_texList[TEX_TREEBODY_0]))error++;
  153. if(!cTex.MakeTextureBind("plants/treebody1.bmp",&m_texList[TEX_TREEBODY_1]))error++;
  154.     //branch
  155.     strcpy(filename+dirlen,"branch2.bmp");
  156.     strcpy(alphaname+dirlen,"branchAlpha2.bmp");
  157. if(!cTex.MakeAlphaTextureBind(filename,alphaname,&m_texList[TEX_BRANCH_0]))error++;
  158.     strcpy(filename+dirlen,"branch1.bmp");
  159.     strcpy(alphaname+dirlen,"branchAlpha1.bmp");
  160. if(!cTex.MakeAlphaTextureBind(filename,alphaname,&m_texList[TEX_BRANCH_1]))error++;
  161.     strcpy(filename+dirlen,"branch3.bmp");
  162.     strcpy(alphaname+dirlen,"branchAlpha3.bmp");
  163. if(!cTex.MakeAlphaTextureBind(filename,alphaname,&m_texList[TEX_BRANCH_2]))error++;
  164.     // bush
  165.     strcpy(filename+dirlen,"bush1.bmp");
  166.     strcpy(alphaname+dirlen,"bushAlpha1.bmp");
  167. if(!cTex.MakeAlphaTextureBind(filename,alphaname,&m_texList[TEX_BUSH_0]))error++;
  168. ///////////////// smf model
  169. if(!cTex.MakeTextureBind("model/soldier/soldier.bmp",&m_texList[TEX_SOILDER]))error++;
  170. if(!cTex.MakeTextureBind("model/soldier/weapon.bmp",&m_texList[TEX_WEAPON]))error++;
  171. if(!cTex.MakeTextureBind("model/soldier/mygun.bmp",&m_texList[TEX_MY_GUN]))error++;
  172. // if(!cTex.MakeAlphaTextureBind("texture/metal.bmp",&m_texList[TEX_METAL]))error++;
  173. ///////////////// house
  174. if(!cTex.MakeTextureBind("model/ms3d/house0.bmp",&m_texList[TEX_HOUSE_0]))error++;
  175. if(!cTex.MakeTextureBind("model/ms3d/house1.bmp",&m_texList[TEX_HOUSE_1]))error++;
  176. if(!cTex.MakeTextureBind("model/ms3d/house2.bmp",&m_texList[TEX_HOUSE_2]))error++;
  177. ///////////////// smoke
  178. if(!cTex.MakeAlphaTextureBind("texture/smoke1.bmp",&m_texList[TEX_SMOKE_0]))error++;
  179. if(!cTex.MakeAlphaTextureBind("texture/gunfire.bmp",&m_texList[TEX_GUN_FIRE]))error++;
  180. //////////////////TEX_NAVIGATOR
  181. if(!cTex.MakeTextureBind("Texture/navigator.bmp",&m_texList[TEX_NAVIGATOR],1,0))error++;
  182. if(!cTex.MakeTextureBind("Texture/help.bmp",&m_texList[TEX_HELP],1,0))error++;
  183. ////////////////////////////
  184. if(error==0)return true;
  185. else 
  186. return false;
  187. }
  188. void  CTexManager::DeleteMissionResource()
  189. {
  190. glDeleteTextures(1,&m_texList[TEX_IMAGE_TEXT]);
  191.     //////////sky
  192. glDeleteTextures(1,&m_texList[TEX_SKY_0]);
  193. glDeleteTextures(1,&m_texList[TEX_SKY_1]);
  194. glDeleteTextures(1,&m_texList[TEX_SKY_2]);
  195. glDeleteTextures(1,&m_texList[TEX_SKY_3]);
  196. glDeleteTextures(1,&m_texList[TEX_SKY_4]);
  197. //////////terrain 
  198. glDeleteTextures(1,&m_texList[TEX_TERRAIN_A1]);
  199. glDeleteTextures(1,&m_texList[TEX_TERRAIN_A2]);
  200. glDeleteTextures(1,&m_texList[TEX_TERRAIN_A3]);
  201. glDeleteTextures(1,&m_texList[TEX_TERRAIN_A4]);
  202. glDeleteTextures(1,&m_texList[TEX_TERRAIN_A5]);
  203. glDeleteTextures(1,&m_texList[TEX_TERRAIN_B1]);
  204. glDeleteTextures(1,&m_texList[TEX_TERRAIN_B2]);
  205. glDeleteTextures(1,&m_texList[TEX_TERRAIN_B3]);
  206. glDeleteTextures(1,&m_texList[TEX_TERRAIN_B4]);
  207. glDeleteTextures(1,&m_texList[TEX_TERRAIN_B5]);
  208. glDeleteTextures(1,&m_texList[TEX_TERRAIN_SKN1]);
  209. glDeleteTextures(1,&m_texList[TEX_TERRAIN_SKN2]);
  210. glDeleteTextures(1,&m_texList[TEX_TERRAIN_SKN3]);
  211. glDeleteTextures(1,&m_texList[TEX_TERRAIN_SKN4]);
  212. // glDeleteTextures(1,&m_texList[TEX_TERRAIN_DETAIL_0]);
  213. //// LensFlare
  214. glDeleteTextures(1,&m_texList[TEX_LENSFLARE_0]);
  215. glDeleteTextures(1,&m_texList[TEX_LENSFLARE_1]);
  216. glDeleteTextures(1,&m_texList[TEX_LENSFLARE_2]);
  217. glDeleteTextures(1,&m_texList[TEX_LENSFLARE_3]);
  218. glDeleteTextures(1,&m_texList[TEX_LENSFLARE_4]);
  219. glDeleteTextures(1,&m_texList[TEX_LENSFLARE_5]);
  220. glDeleteTextures(1,&m_texList[TEX_LENSFLARE_6]);
  221. ///// plants
  222. glDeleteTextures(1,&m_texList[TEX_TREEBODY_0]);
  223. glDeleteTextures(1,&m_texList[TEX_TREEBODY_1]);
  224. glDeleteTextures(1,&m_texList[TEX_BRANCH_0]);
  225. glDeleteTextures(1,&m_texList[TEX_BRANCH_1]);
  226. glDeleteTextures(1,&m_texList[TEX_BRANCH_2]);
  227. glDeleteTextures(1,&m_texList[TEX_BUSH_0]);
  228. glDeleteTextures(1,&m_texList[TEX_BUSH_1]);
  229. /////////////model
  230. glDeleteTextures(1,&m_texList[TEX_SOILDER]);
  231. glDeleteTextures(1,&m_texList[TEX_WEAPON]);
  232. glDeleteTextures(1,&m_texList[TEX_MY_GUN]);
  233. // glDeleteTextures(1,&m_texList[TEX_METAL]);
  234. //////////house
  235. glDeleteTextures(1,&m_texList[TEX_HOUSE_0]);
  236. glDeleteTextures(1,&m_texList[TEX_HOUSE_1]);
  237. glDeleteTextures(1,&m_texList[TEX_HOUSE_2]);
  238. ////////////smoke
  239. glDeleteTextures(1,&m_texList[TEX_SMOKE_0]);
  240. glDeleteTextures(1,&m_texList[TEX_GUN_FIRE]);
  241. /////////////navigaor
  242. glDeleteTextures(1,&m_texList[TEX_NAVIGATOR]);
  243. glDeleteTextures(1,&m_texList[TEX_HELP]);
  244. }
  245. //////////////////////////////////////////////////
  246. bool  CTexManager::CreateTempMenuResource()
  247. {
  248.     CTexture cTex;
  249. int  error=0;
  250. ///////////////////image text
  251. //  if(!cTex.MakeTextureBind("texture/myfont.BMP",&m_texList[TEX_IMAGE_TEXT],0,0))error++;
  252. // CImgText::m_texFont=m_texList[TEX_IMAGE_TEXT];
  253. ///////////// cursor
  254. if(!cTex.MakeAlphaTextureBind("texture/cur16.BMP","texture/cur16Alpha.bmp",&m_texList[TEX_MENU_CURSOR]))error++;
  255.     //////////// bkg
  256. if(!cTex.MakeScreenTextureBind(&m_texList[TEX_SCREEN_CAPTURE]))error++;
  257. if(error==0)return true;
  258. else 
  259. return false;
  260. }
  261. void  CTexManager::DeleteTempMenuResource()
  262. {
  263. // glDeleteTextures(1,&m_texList[TEX_IMAGE_TEXT]);
  264. glDeleteTextures(1,&m_texList[TEX_MENU_CURSOR]);
  265. glDeleteTextures(1,&m_texList[TEX_SCREEN_CAPTURE]);
  266. }
  267. /////////////////////////////////////////////////////
  268. unsigned int CTexManager::GetTextureID(int texDefineName)
  269. {
  270. if(texDefineName>0 && texDefineName<MAX_TEXTURE_NUM)
  271.         return m_texList[texDefineName];
  272. else
  273. return 0;
  274. }