00001 00008 /* 00009 This file is part of Teapot Colony Wars. 00010 00011 Teapot Colony Wars is free software: you can redistribute it and/or modify 00012 it under the terms of the GNU General Public License as published by 00013 the Free Software Foundation, either version 2 of the License, or 00014 (at your option) any later version. 00015 00016 Teapot Colony Wars is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 GNU General Public License for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with Teapot Colony Wars. If not, see <http://www.gnu.org/licenses/>. 00023 */ 00024 00025 #ifndef IMAGE_H 00026 #define IMAGE_H 00027 00028 #include <fstream> 00029 #include <GL/glut.h> 00030 00041 typedef struct _BITMAPFILEHEADER { 00043 short bfType; 00045 int bfSize; 00047 short bfReserved1; 00049 short bfReserved2; 00051 int bfOffBits; 00052 } BITMAPFILEHEADER; 00053 00064 typedef struct _BITMAPINFOHEADER { 00066 int biSize; 00068 int biWidth; 00070 int biHeight; 00074 short biPlanes; 00076 short biBitCount; 00080 int biCompression; 00085 int biSizeImage; 00090 int biXPelsPerMeter; 00094 int biYPelsPerMeter; 00099 int biClrUsed; 00104 int biClrImportant; 00105 } BITMAPINFOHEADER; 00106 00117 typedef struct _RGBQUAD { 00119 char rgbBlue; 00121 char rgbGreen; 00123 char rgbRed; 00125 char rgbReserved; 00126 } RGBQUAD; 00127 00131 class Image 00132 { 00133 protected: 00134 00136 GLuint _width; 00137 00139 GLuint _height; 00140 00142 GLubyte *_pixels; 00143 00150 int readInt(std::ifstream &input); 00151 00158 short readShort(std::ifstream &input); 00159 00166 void readBMPFileHeader(std::ifstream &input, BITMAPFILEHEADER *bfh); 00167 00174 void readBMPInfoHeader(std::ifstream &input, BITMAPINFOHEADER *bih); 00175 00183 void readBMPColorTable(std::ifstream &input, int end, RGBQUAD *table); 00184 00190 void loadBMP(const char* filename); 00191 00192 public: 00193 00199 Image(const char* filename); 00200 00207 Image(GLuint width, GLuint height); 00208 00212 virtual ~Image(); 00213 00219 GLuint getWidth() {return _width;} 00220 00226 GLuint getHeight() {return _height;} 00227 00233 GLubyte* getPixels() {return _pixels;} 00234 00240 GLuint genTexture1D(); 00241 00247 GLuint genTexture2D(); 00248 }; 00249 00250 #endif // IMAGE_H