Data.cpp
上传用户:yunyi28
上传日期:2021-04-25
资源大小:6978k
文件大小:2k
源码类别:

分形几何

开发平台:

Visual C++

  1. #include "Data.h"
  2. list<TreeType> treeType;
  3. list<Tree> trees;
  4. GLuint bmptexture[11];
  5. GLuint texture[1];
  6. AUX_RGBImageRec *LoadBMP(char *filename);
  7. int LoadGLTexture();
  8. void InitData()
  9. {
  10. glGenTextures(10, &bmptexture[0]);
  11. if( !BMP::LoadBMPTexture(&bmptexture[0],"../Texture/treebody.bmp") ||
  12. !BMP::LoadBMPTexture(&bmptexture[2],"../Texture/Image1.bmp") ||
  13. !BMP::MakeAlphaTextureBind("../Texture/Image1.bmp",&bmptexture[3])
  14. )
  15. {
  16. MessageBox(NULL,"Can't open bmp",NULL,NULL);
  17. return;
  18. }
  19. if(!LoadGLTexture())
  20. return ;
  21. }
  22. AUX_RGBImageRec *LoadBMP(char *filename)
  23. {
  24. FILE *f=NULL;
  25. if(!filename)
  26. {
  27. return NULL;
  28. }
  29. f = fopen(filename,"r");
  30. if(f)
  31. {
  32. fclose(f);
  33. // wchar_t *pwText;
  34. // int size=MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, -1);
  35. // pwText = new wchar_t[size];
  36. // MultiByteToWideChar(CP_ACP, 0, filename, -1, pwText, size);
  37. // delete []pwText;
  38. return auxDIBImageLoad(filename);
  39. }
  40. return NULL;
  41. }
  42. int LoadGLTexture()
  43. {
  44. int status=FALSE;
  45. AUX_RGBImageRec *TextureImage[1];
  46. memset(TextureImage,0,sizeof(void*)*1);
  47. if(TextureImage[0]=LoadBMP("../Texture/bmp1.bmp"))
  48. {
  49. status=TRUE;
  50. glGenTextures(1,&texture[0]);
  51. glBindTexture(GL_TEXTURE_2D,texture[0]);
  52. glTexImage2D(GL_TEXTURE_2D,0,3,TextureImage[0]->sizeX,TextureImage[0]->sizeY,0,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[0]->data);
  53. // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  54. // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  55. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
  56. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
  57. }
  58. if(TextureImage[0])
  59. {
  60. if(TextureImage[0]->data)
  61. free(TextureImage[0]->data);
  62. free(TextureImage[0]);
  63. }
  64. return status;
  65. }