Texture.h
上传用户:hcfgz168
上传日期:2011-09-11
资源大小:116k
文件大小:3k
源码类别:

OpenGL

开发平台:

WINDOWS

  1. //********************************************
  2. // Texture.h
  3. //********************************************
  4. // class CTexture
  5. //********************************************
  6. // This object stores a bitmap image used as
  7. // an OpenGL texture.
  8. // Files are stored as .bmp or .jpg format. 
  9. // Depth are currently 24 or 32 bits,
  10. // Modes are : RGB, RGBA (alpha layer).
  11. //********************************************
  12. // pierre.alliez@cnet.francetelecom.fr
  13. // Created : 17/12/97
  14. // Modified : 18/02/98
  15. //********************************************
  16. #ifndef _TEXTURE_
  17. #define _TEXTURE_
  18. class CTexture : public CObject
  19. {
  20. // Members datas
  21. private :
  22. unsigned char *m_pData;    // datas
  23. unsigned int   m_Width;    // width (pixels)
  24. unsigned int   m_Height;   // height (pixels)
  25. unsigned int   m_Depth;    // bits per pixel 
  26. CString        m_FileName; // texture image file name
  27. BITMAPINFOHEADER m_Header;      // image header (display on device context)
  28. unsigned int     m_WidthByte32; // width (in bytes, and 32 bits aligned)
  29. public :
  30. // Construction / destruction
  31. CTexture();
  32. virtual ~CTexture();
  33. // File reading
  34. int ReadFile(char *filename,unsigned int width=-1,
  35.            unsigned int height=-1,unsigned int depth=-1);
  36. int ReadFileBMP(char *filename);
  37. int ReadFileRAW(char *filename,unsigned int width,
  38.               unsigned int height,unsigned int depth);
  39. // File saving
  40. int SaveFile(char *filename);
  41. int SaveFileBMP(char *filename);
  42. int SaveFileRAW(char *filename);
  43. // Datas (explicit inline functions)
  44. unsigned char *GetData(void) { return m_pData; }
  45. unsigned int GetWidth(void)  { return m_Width; }
  46. unsigned int GetHeight(void) { return m_Height;}
  47. unsigned int GetDepth(void)  { return m_Depth; }
  48. CString GetFileName(void)    { return m_FileName; }
  49. // Misc
  50. int IsValid();
  51. int SameSize(CTexture *pTexture);
  52. int BGRtoRGB(void);
  53. static int HigherPowerOfTwo(int value);
  54. static int LowerPowerOfTwo(int value);
  55. // Updating
  56. void UpdateWidthByte32();
  57. void UpdateHeader();
  58. unsigned int WidthByte32(unsigned int width,unsigned int depth);
  59. // Clipboard
  60. HANDLE ExportHandle();
  61. // Alpha
  62. int HasAlpha() { return (m_Depth == 32); }
  63. int AddAlphaLayer(unsigned char alpha);
  64. int SetAlphaLayer(unsigned char alpha);
  65. int PutAlpha(CTexture *pTexture); // Put an alpha layer from grey scale
  66. // DuplicateMirror
  67. int DuplicateMirror(int left=0,int top=0,int right=-1,int bottom=-1);
  68. int DuplicateRepeatWidth(int left=0,int top=0,int right=-1,int bottom=-1);
  69. int Extract(int left=0,int top=0,int right=-1,int bottom=-1);
  70. // Display
  71. int Draw(CDC *pDC,int xOffset=0,int yOffset=0, int width=-1, int height=-1);
  72. // Buffer
  73. int ReadBuffer(unsigned char *buffer, int width, int height, int depth);
  74. int ReadBuffer(float *buffer, int width, int height, int depth);
  75. int Grey(unsigned int x,unsigned int y);
  76. void Color(unsigned int x,unsigned int y,
  77. unsigned char *pRed,unsigned char *pGreen,unsigned char *pBlue);
  78. private :
  79. // Memory
  80. int Alloc(unsigned int width,unsigned int height,unsigned int depth);
  81. void Free(void);
  82. };
  83. #endif // _TEXTURE_