• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

src/render/src/Gui.cpp

Go to the documentation of this file.
00001 //#pragma once
00002 //#include "../pch.h"
00003 //
00004 //typedef void (__stdcall * PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex);
00005 //PFNGLDRAWELEMENTSBASEVERTEXPROC glDrawElementsBaseVertex_gui;
00006 //
00007 //Gui::Gui(void)
00008 //{
00009 //}
00010 //
00011 //Gui::~Gui(void)
00012 //{
00013 //}
00014 //
00015 //
00016 //void Gui::init(void)
00017 //{
00018 //      glDrawElementsBaseVertex_gui = (PFNGLDRAWELEMENTSBASEVERTEXPROC)wglGetProcAddress("glDrawElementsBaseVertex");
00019 //      if(glDrawElementsBaseVertex_gui == 0){
00020 //              printf("%s","glDrawElementsBaseVertex not available.");
00021 //              exit(0xff);
00022 //      }
00023 //
00024 //      char* offset = 0;
00025 //      m_vertexSize = sizeof(GuiVertex);
00026 //
00027 //      glGenBuffers(1, &m_vertexBuffer);
00028 //      glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
00029 //      glBufferData(GL_ARRAY_BUFFER,m_vertexSize * MAX_VERTICES, 0, GL_STATIC_DRAW);
00030 //
00031 //      CHECK_GL_ERROR
00032 //
00033 //      glGenVertexArrays(1, &m_vertexArray);
00034 //      glBindVertexArray(m_vertexArray);
00035 //
00036 //      for(int i = 0; i < 3; i++) {
00037 //              glEnableVertexAttribArray(i);
00038 //              CHECK_GL_ERROR
00039 //              glVertexAttribPointer(i, 2, GL_FLOAT, GL_FALSE, m_vertexSize, offset);
00040 //              CHECK_GL_ERROR
00041 //              offset += 4 * sizeof(float);
00042 //      }
00043 //
00044 //      glGenBuffers(1, &m_indexBuffer);
00045 //      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer);
00046 //      glBufferData(GL_ELEMENT_ARRAY_BUFFER, 2 * MAX_INDICES, 0, GL_STATIC_DRAW);
00047 //
00048 //      CHECK_GL_ERROR
00049 //
00050 //      //Reserve Texture
00051 //      glGenTextures(1,&m_colorTexture);
00052 //      glActiveTexture(GL_TEXTURE2);
00053 //      glBindTexture(GL_TEXTURE_2D_ARRAY, m_colorTexture);
00054 //
00055 //      // set default parameters
00056 //      glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00057 //      glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00058 //      glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_R, GL_REPEAT);
00059 //      glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
00060 //      glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
00061 //
00062 //      glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA, TEXTURE_HEIGHT, TEXTURE_WIDTH, MAX_TEXTURES, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
00063 //
00064 //      // set size and vertex count
00065 //      m_vertexSize = uint(offset);
00066 //      m_vertexCount = 0;
00067 //      m_indexCount = 0;
00068 //      m_textureCount = 0;
00069 //
00070 //      m_shader.setIsGui(true);
00071 //      if(!m_shader.init(TEXT("../external/shader/uiShader.vert"), TEXT("../external/shader/uiShader.frag"))) {
00072 //              printf("Shader fuckup!");
00073 //              exit(0xff);
00074 //      }
00075 //
00076 //      m_uniformTexIdx = m_shader.getUniform("texIdx");
00077 //      m_samplerColor = m_shader.getUniform("colorArray");
00078 //
00079 //      m_samplerColor.set1i(2);
00080 //}
00081 //
00082 //void Gui::draw()
00083 //{
00084 //      m_shader.use();
00085 //      
00086 //      glDisable(GL_DEPTH_TEST);
00087 //
00088 //      glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
00089 //      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer);
00090 //
00091 //      glActiveTexture(GL_TEXTURE2);
00092 //      glBindTexture(GL_TEXTURE_2D_ARRAY, m_colorTexture);
00093 //
00094 //      //Do drawing
00095 //      for(int i = 0; i < m_controlCount; i++) {
00096 //              pIControl &control = m_controlList[i];
00097 //              m_uniformTexIdx.set1f((float)control->getTextureIndex());
00098 //              glDrawElementsBaseVertex_gui(GL_TRIANGLES, control->getIndexCount(), GL_UNSIGNED_SHORT, control->getBaseIndex(), control->getBaseVertex());
00099 //      }
00100 //
00101 //      glEnable(GL_DEPTH_TEST);
00102 //}
00103 //
00104 //
00105 //pIControl Gui::createLabel(float x, float y, float width, float height, wchar *fileTexture)
00106 //{
00107 //      GuiData guiData;
00108 //
00109 //      guiData.vertexSize = sizeof(GuiVertex);
00110 //      guiData.vertexCount = 4;
00111 //      guiData.indexCount = 4;
00112 //      
00113 //
00114 //      void *memory = malloc(m_vertexSize * 4 + 2 * 4);
00115 //      GuiVertex *vertices = (GuiVertex*)memory;
00116 //      ushort *indices = (ushort*)&vertices[4];
00117 //
00118 //      vertices[0].position[0] = x; vertices[0].position[1] =  y;
00119 //      vertices[0].position[2] = 0.0f; vertices[0].position[3] = 0.0f;
00120 //      vertices[0].color[0] = 0.0f; vertices[0].color[1] = 0.0f;
00121 //      vertices[0].color[2] = 0.0f; vertices[0].color[3] = 0.0f;
00122 //      vertices[0].uv[0] = 0.0f; vertices[0].uv[1] = 0.0f;
00123 //      vertices[0].uv[2] = 0.0f; vertices[0].uv[3] = 0.0f;
00124 //
00125 //      vertices[1].position[0] = x + width; vertices[1].position[1] =  y;
00126 //      vertices[1].position[2] = 0.0f; vertices[1].position[3] = 0.0f;
00127 //      vertices[1].color[0] = 0.0f; vertices[1].color[1] = 0.0f;
00128 //      vertices[1].color[2] = 0.0f; vertices[1].color[3] = 0.0f;
00129 //      vertices[1].uv[0] = 1.0f; vertices[1].uv[1] = 0.0f;
00130 //      vertices[1].uv[2] = 0.0f; vertices[1].uv[3] = 0.0f;
00131 //
00132 //      vertices[2].position[0] = x + width; vertices[2].position[1] =  y + height;
00133 //      vertices[2].position[2] = 0.0f; vertices[2].position[3] = 0.0f;
00134 //      vertices[2].color[0] = 0.0f; vertices[2].color[1] = 0.0f;
00135 //      vertices[2].color[2] = 0.0f; vertices[2].color[3] = 0.0f;
00136 //      vertices[2].uv[0] = 1.0f; vertices[2].uv[1] = 1.0f;
00137 //      vertices[2].uv[2] = 0.0f; vertices[2].uv[3] = 0.0f;
00138 //
00139 //      vertices[3].position[0] = x; vertices[3].position[1] =  y + height;
00140 //      vertices[3].position[2] = 0.0f; vertices[3].position[3] = 0.0f;
00141 //      vertices[3].color[0] = 0.0f; vertices[3].color[1] = 0.0f;
00142 //      vertices[3].color[2] = 0.0f; vertices[3].color[3] = 0.0f;
00143 //      vertices[3].uv[0] = 0.0f; vertices[3].uv[1] = 1.0f;
00144 //      vertices[3].uv[2] = 0.0f; vertices[3].uv[3] = 0.0f;
00145 //
00146 //      indices[0] = 0; indices[1] = 1; 
00147 //      indices[2] = 2; indices[3] = 3; 
00148 //
00149 //      guiData.vertices = vertices;
00150 //      guiData.indices = indices;
00151 //
00152 //      glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
00153 //      glBufferSubData(GL_ARRAY_BUFFER, GLintptr(m_vertexSize * m_vertexCount), GLsizeiptr(m_vertexSize * 4), guiData.vertices);
00154 //
00155 //      CHECK_GL_ERROR
00156 //
00157 //      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer);
00158 //      glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, GLintptr(sizeof(ushort) * m_indexCount), GLsizeiptr(sizeof(ushort) * 4), guiData.indices);
00159 //
00160 //      CHECK_GL_ERROR
00161 //
00162 //      
00163 //
00164 //      //load Texture
00165 //      MipMap mipmap;
00166 //      mipmap.width = 256;
00167 //      mipmap.height = 256;
00168 //
00169 //      Pixel* textureData = 0;
00170 //
00171 //      int colorWidth = 0, colorHeight = 0; 
00172 //      /*if(!loadBMP(fileTexture, colorWidth, colorHeight, &textureData))
00173 //              return 0;*/
00174 //
00175 //      mipmap.data = textureData;
00176 //
00177 //      glActiveTexture(GL_TEXTURE2);
00178 //      glBindTexture(GL_TEXTURE_2D_ARRAY, m_colorTexture);
00179 //
00180 //      glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0,0,0, m_textureCount, 256, 256, 1, GL_RGBA, GL_UNSIGNED_BYTE, &mipmap);
00181 //
00182 //      //pIControl control = new Control(m_vertexCount, 4, (void*) (sizeof(ushort) * m_indexCount), 4, m_textureCount);
00183 //
00184 //      m_vertexCount += 4;
00185 //      m_indexCount += 4;
00186 //      m_textureCount++;
00187 //
00188 //      return control;
00189 //}
00190 //
00191 //
00192 //void Gui::addControl(pIControl control)
00193 //{
00194 //      m_controlList.push_back(control);
00195 //      m_controlCount++;
00196 //}
00197 //
00198 //
00199 //bool Gui::loadTextureData(const wchar* colorFilename, const wchar* normalFilename, const wchar* heightFilename, TextureData& out)
00200 //{
00201 //      Pixel* colorData = 0;
00202 //      Pixel* normalData = 0;
00203 //      Pixel* heightData = 0;
00204 //      int widthColor = 0, heightColor = 0;
00205 //      int widthDetail = 0, heightDetail = 0;
00206 //      bool ok = true;
00207 //
00208 //      ok = loadUnknown(colorFilename, widthColor, heightColor, 0);
00209 //      if(ok) ok = loadUnknown(colorFilename, widthColor, heightColor, &colorData);
00210 //      ok = loadUnknown(normalFilename, widthDetail, heightDetail, 0);
00211 //      if(ok) ok = loadUnknown(normalFilename, widthDetail, heightDetail, &normalData);
00212 //      if(ok) ok = loadUnknown(heightFilename, widthDetail, heightDetail, &heightData);
00213 //
00214 //      if(ok == false)
00215 //      {
00216 //              SAVEFREE(colorData);
00217 //              SAVEFREE(normalData);
00218 //              SAVEFREE(heightData);
00219 //              return false;
00220 //      }
00221 //
00222 //      int mipmapsColor = 0;
00223 //      int mipmapsDetail = 0;
00224 //      int mipmapPixelsColor = 0;
00225 //      int mipmapPixelsDetail = 0;
00226 //      MipMap* colorMipmaps;
00227 //      MipMap* detailMipmaps;
00228 //
00229 //      for(int w=widthColor; w>0; mipmapPixelsColor+=w*w, w/=2, mipmapsColor++);
00230 //      for(int w=widthDetail; w>0; mipmapPixelsDetail+=w*w, w/=2, mipmapsDetail++);
00231 //
00232 //      void* mem = malloc(sizeof(MipMap)*(mipmapsColor+mipmapsDetail) + sizeof(Pixel)*(mipmapPixelsColor+mipmapPixelsDetail));
00233 //
00234 //      colorMipmaps = (MipMap*)mem;
00235 //      detailMipmaps = &colorMipmaps[mipmapsColor];
00236 //      Pixel* colorPixels = (Pixel*)&detailMipmaps[mipmapsDetail];
00237 //      Pixel* detailPixels = &colorPixels[mipmapPixelsColor];
00238 //
00239 //      for(int i=0, w=widthColor, curPixel=0; i<mipmapsColor; curPixel+=w*w, w/=2, i++)
00240 //      {
00241 //              colorMipmaps[i].width = w;
00242 //              colorMipmaps[i].height = w;
00243 //              colorMipmaps[i].data = &colorPixels[curPixel];
00244 //      }
00245 //
00246 //      for(int i=0, w=widthDetail, curPixel=0; i<mipmapsDetail; curPixel+=w*w, w/=2, i++)
00247 //      {
00248 //              detailMipmaps[i].width = w;
00249 //              detailMipmaps[i].height = w;
00250 //              detailMipmaps[i].data = &detailPixels[curPixel];
00251 //      }
00252 //
00253 //      // copy loaded data
00254 //      for(int y=0; y<colorMipmaps[0].height; y++)
00255 //      {
00256 //              for(int x=0; x<colorMipmaps[0].width; x++)
00257 //                      colorMipmaps[0].data[y*widthColor+x] = colorData[y*widthColor+x];
00258 //      }
00259 //
00260 //      // compute color mipmaps
00261 //      for(int i=0; i<mipmapsColor-1; i++)
00262 //      {
00263 //              for(int y=0; y<colorMipmaps[i+1].height; y++)
00264 //              {
00265 //                      for(int x=0; x<colorMipmaps[i+1].width; x++)
00266 //                      {
00267 //                              int color[4];
00268 //                              for(int c=0; c<4; color[c]  = colorMipmaps[i].data[((y+0)* colorMipmaps[i].width + x + 0)*2].canal[c], c++);
00269 //                              for(int c=0; c<4; color[c] += colorMipmaps[i].data[((y+0)* colorMipmaps[i].width + x + 1)*2].canal[c], c++);
00270 //                              for(int c=0; c<4; color[c] += colorMipmaps[i].data[((y+1)* colorMipmaps[i].width + x + 0)*2].canal[c], c++);
00271 //                              for(int c=0; c<4; color[c] += colorMipmaps[i].data[((y+1)* colorMipmaps[i].width + x + 1)*2].canal[c], c++);
00272 //                              for(int c=0; c<4; colorMipmaps[i+1].data[y * colorMipmaps[i+1].width + x].canal[c] = uchar(color[c]/4), c++);
00273 //                      }
00274 //              }
00275 //      }
00276 //
00277 //      // copy loaded height data
00278 //      for(int y=0; y<detailMipmaps[0].height; y++)
00279 //      {
00280 //              for(int x=0; x<detailMipmaps[0].width; x++)
00281 //              {
00282 //                      normalData[y*widthDetail+x].a = heightData[y*widthDetail+x].r;
00283 //                      detailMipmaps[0].data[y*widthDetail+x] = normalData[y*widthDetail+x];
00284 //              }
00285 //      }
00286 //
00287 //      // compute color mipmaps
00288 //      for(int i=0; i<mipmapsDetail-1; i++)
00289 //      {
00290 //              for(int y=0; y<detailMipmaps[i].height/2; y++)
00291 //              {
00292 //                      for(int x=0; x<detailMipmaps[i].width/2; x++)
00293 //                      {
00294 //                              int normal[4];
00295 //                              for(int c=0; c<4; normal[c]  = detailMipmaps[i].data[((y+0)* detailMipmaps[i].width + x + 0)*2].canal[c], c++);
00296 //                              for(int c=0; c<4; normal[c] += detailMipmaps[i].data[((y+0)* detailMipmaps[i].width + x + 1)*2].canal[c], c++);
00297 //                              for(int c=0; c<4; normal[c] += detailMipmaps[i].data[((y+1)* detailMipmaps[i].width + x + 0)*2].canal[c], c++);
00298 //                              for(int c=0; c<4; normal[c] += detailMipmaps[i].data[((y+1)* detailMipmaps[i].width + x + 1)*2].canal[c], c++);
00299 //                              for(int c=0; c<4; detailMipmaps[i+1].data[y * detailMipmaps[i+1].width + x].canal[c] = uchar(normal[c]/4), c++);
00300 //                      }
00301 //              }
00302 //      }
00303 //
00304 //      // free temporary data
00305 //      SAVEFREE(colorData);
00306 //      SAVEFREE(normalData);
00307 //      SAVEFREE(heightData);
00308 //
00309 //      // fill output structure
00310 //      out.mipmapsColor = mipmapsColor;
00311 //      out.mipmapsDetail = mipmapsDetail;
00312 //      out.color = colorMipmaps;
00313 //      out.detail = detailMipmaps;
00314 //      return true;
00315 //}
00316 //
00317 //
00318 //bool Gui::loadUnknown(const wchar* filename, int& width, int& height, Pixel** outData)
00319 //{
00320 //      bool ok = true;
00321 //      size_t filenameLength = wcslen(filename);
00322 //
00323 //      if(wcscmp(&filename[filenameLength-4], TEXT(".bmp")) == 0)
00324 //              ok = loadBMP(filename, width, height, outData);
00325 //      else if(wcscmp(&filename[filenameLength-4], TEXT(".tga")) == 0)
00326 //              //ok = loadTGA(filename, width, height, outData);
00327 //      else
00328 //              return false;
00329 //
00330 //      if(outData == 0 && width != height)
00331 //              return false;
00332 //
00333 //      return ok;
00334 //}
00335 //
00336 //struct BMP_SIGNATURE {
00337 //      BMP_SIGNATURE() {
00338 //              this->c[0] = 'B';
00339 //              this->c[1] = 'M';
00340 //      }
00341 //      union {
00342 //              unsigned short int s;//= 'MB';
00343 //              unsigned char c[2];
00344 //      };
00345 //};
00346 //
00347 //const BMP_SIGNATURE bmpSignature;
00348 //const unsigned short int BITMAP_SIGNATURE = bmpSignature.s;
00349 //
00350 //typedef struct {
00351 //      unsigned short int Signature;
00352 //      unsigned int Size;
00353 //      unsigned int Reserved;
00354 //      unsigned int BitsOffset;
00355 //} BITMAP_FILEHEADER;
00356 //
00357 //#define BITMAP_FILEHEADER_SIZE 14
00358 //
00359 //typedef struct {
00360 //      unsigned int HeaderSize;
00361 //      int Width;
00362 //      int Height;
00363 //      unsigned short int Planes;
00364 //      unsigned short int BitCount;
00365 //      unsigned int Compression;
00366 //      unsigned int SizeImage;
00367 //      int PelsPerMeterX;
00368 //      int PelsPerMeterY;
00369 //      unsigned int ClrUsed;
00370 //      unsigned int ClrImportant;
00371 //      unsigned int RedMask;
00372 //      unsigned int GreenMask;
00373 //      unsigned int BlueMask;
00374 //      unsigned int AlphaMask;
00375 //      unsigned int CsType;
00376 //      unsigned int Endpoints[9]; // see http://msdn2.microsoft.com/en-us/library/ms536569.aspx
00377 //      unsigned int GammaRed;
00378 //      unsigned int GammaGreen;
00379 //      unsigned int GammaBlue;
00380 //} BITMAP_HEADER;
00381 //
00382 //typedef struct {
00383 //      unsigned char Red;
00384 //      unsigned char Green;
00385 //      unsigned char Blue;
00386 //      unsigned char Alpha;
00387 //} RGBA;
00388 //
00389 //typedef struct {
00390 //      unsigned char Blue;
00391 //      unsigned char Green;
00392 //      unsigned char Red;
00393 //      unsigned char Alpha;
00394 //} BGRA;
00395 //
00396 //typedef struct {
00397 //      unsigned char Blue;
00398 //      unsigned char Green;
00399 //      unsigned char Red;
00400 //} BGR;
00401 //
00402 //typedef struct {
00403 //      unsigned short int Blue:5;
00404 //      unsigned short int Green:5;
00405 //      unsigned short int Red:5;
00406 //      unsigned short int Reserved:1;
00407 //} BGR16;
00408 //
00409 //uint ShiftRightByMask(uint Color, uint Mask, uint DistributeToBits = 8) {
00410 //      if (Mask == 0) return 0;
00411 //
00412 //      uint ShiftCount = 0;
00413 //      uint Test = 0x00000001;
00414 //
00415 //      while((ShiftCount<32) && !(Mask & Test)){
00416 //              Test <<= 1;
00417 //              ShiftCount++;
00418 //      }
00419 //      
00420 //      uint BitCount = 32;
00421 //      Test = 0x80000000;
00422 //
00423 //      while(BitCount && !((Mask >> ShiftCount) & Test)){
00424 //              Test >>= 1;
00425 //              BitCount--;
00426 //      }
00427 //
00428 //      uint BaseColor = (Color & Mask) >> ShiftCount;
00429 //
00430 //      if(DistributeToBits > BitCount){
00431 //              /* We have to fill lower bits */
00432 //              uint BitsToFill = DistributeToBits - BitCount;
00433 //              while(BitsToFill--) {
00434 //                      BaseColor <<= 1;
00435 //                      if(BaseColor & 1)
00436 //                              BaseColor |= 1;
00437 //              }
00438 //      }else if(DistributeToBits < BitCount){
00439 //              BaseColor >>= (BitCount - DistributeToBits);
00440 //      }
00441 //      return BaseColor;
00442 //}
00443 //
00444 //bool Level::loadBMP(const wchar* filename, int& width, int& height, Pixel** outData){
00445 //      FILE* file = 0;
00446 //      BITMAP_FILEHEADER m_BitmapFileHeader;
00447 //      BITMAP_HEADER m_BitmapHeader;
00448 //      RGBA* m_BitmapData = 0;
00449 //      uchar *Line = 0;
00450 //      uint m_BitmapSize = 0;
00451 //      BGRA m_ColorTable[256];
00452 //      uint m_ColorTableSize = 0;
00453 //      int bmpWidth = 0, bmpHeight = 0;
00454 //
00455 //      #define SAVEEXIT(rs) {\
00456 //              if(file){fclose(file);file=0;}\
00457 //              SAVEFREE(m_BitmapData);\
00458 //              SAVEFREE(Line);\
00459 //              return rs;}
00460 // 
00461 //      if(_wfopen_s(&file, filename, TEXT("rb")) != 0)
00462 //              return false;
00463 //      
00464 //      fread(&m_BitmapFileHeader, BITMAP_FILEHEADER_SIZE, 1, file);
00465 //      if(m_BitmapFileHeader.Signature != BITMAP_SIGNATURE)
00466 //              return false;
00467 //
00468 //      fread(&m_BitmapHeader, sizeof(BITMAP_HEADER), 1, file);
00469 //      
00470 //      /* Load Color Table */
00471 //      fseek(file, BITMAP_FILEHEADER_SIZE + m_BitmapHeader.HeaderSize, SEEK_SET);
00472 //      
00473 //      switch(m_BitmapHeader.BitCount){
00474 //              case 1: m_ColorTableSize = 2; break;
00475 //              case 4: m_ColorTableSize = 16; break;
00476 //              case 8: m_ColorTableSize = 256; break;
00477 //              default: break;
00478 //      }
00479 //      
00480 //      if(m_ColorTableSize>0)
00481 //              fread(m_ColorTable, sizeof(BGRA), m_ColorTableSize, file);
00482 //
00483 //      /* ... Color Table for 16 or 32 Bit Images are not supported yet */     
00484 //      bmpWidth = m_BitmapHeader.Width < 0 ? -m_BitmapHeader.Width : m_BitmapHeader.Width;
00485 //      bmpHeight = m_BitmapHeader.Height < 0 ? -m_BitmapHeader.Height : m_BitmapHeader.Height;
00486 //
00487 //      if(width > 0 && height > 0 && width != bmpWidth && height != bmpHeight){
00488 //              fclose(file);
00489 //              return false;
00490 //      }
00491 //
00492 //      width = bmpWidth;
00493 //      height = bmpHeight;
00494 //
00495 //      if(outData == 0){
00496 //              fclose(file);
00497 //              return true;
00498 //      }
00499 //
00500 //      m_BitmapSize = bmpWidth * bmpHeight;
00501 //      m_BitmapData = (RGBA*)malloc(sizeof(RGBA)*m_BitmapSize);
00502 //      
00503 //      uint LineWidth = (bmpWidth * m_BitmapHeader.BitCount/8 + 3) & ~3;
00504 //      Line = (uchar*)malloc(sizeof(uchar)*LineWidth);
00505 //      
00506 //      fseek(file, m_BitmapFileHeader.BitsOffset, SEEK_SET);
00507 //      
00508 //      int Index = 0;
00509 //      
00510 //      switch(m_BitmapHeader.Compression){
00511 //              // no compression
00512 //              case 0:{
00513 //                      for (int i = 0; i < bmpHeight; i++) {
00514 //                              fread(Line, LineWidth, 1, file);
00515 //                              uchar *LinePtr = Line;
00516 //
00517 //                              switch(m_BitmapHeader.BitCount) {
00518 //                                      case 1:
00519 //                                              for(int j = 0; j < bmpWidth; j++){
00520 //                                                      uint Color = *((uchar*) LinePtr);
00521 //                                                      for (int k = 0; k < 8; k++) {
00522 //                                                              m_BitmapData[Index].Red   = m_ColorTable[Color & 0x80 ? 1 : 0].Red;
00523 //                                                              m_BitmapData[Index].Green = m_ColorTable[Color & 0x80 ? 1 : 0].Green;
00524 //                                                              m_BitmapData[Index].Blue  = m_ColorTable[Color & 0x80 ? 1 : 0].Blue;
00525 //                                                              m_BitmapData[Index].Alpha = m_ColorTable[Color & 0x80 ? 1 : 0].Alpha;
00526 //                                                              Index++;
00527 //                                                              Color <<= 1;
00528 //                                                      }
00529 //                                                      LinePtr++;
00530 //                                                      j += 7;
00531 //                                              }
00532 //                                              break;
00533 //                                      case 4:
00534 //                                              for(int j = 0; j < bmpWidth; j++){
00535 //                                                      uint Color = *((uchar*) LinePtr);
00536 //                                                      m_BitmapData[Index].Red   = m_ColorTable[(Color >> 4) & 0x0f].Red;
00537 //                                                      m_BitmapData[Index].Green = m_ColorTable[(Color >> 4) & 0x0f].Green;
00538 //                                                      m_BitmapData[Index].Blue  = m_ColorTable[(Color >> 4) & 0x0f].Blue;
00539 //                                                      m_BitmapData[Index].Alpha = m_ColorTable[(Color >> 4) & 0x0f].Alpha;
00540 //                                                      Index++;
00541 //                                                      m_BitmapData[Index].Red   = m_ColorTable[Color & 0x0f].Red;
00542 //                                                      m_BitmapData[Index].Green = m_ColorTable[Color & 0x0f].Green;
00543 //                                                      m_BitmapData[Index].Blue  = m_ColorTable[Color & 0x0f].Blue;
00544 //                                                      m_BitmapData[Index].Alpha = m_ColorTable[Color & 0x0f].Alpha;
00545 //                                                      Index++;
00546 //                                                      LinePtr++;
00547 //                                                      j++;
00548 //                                              }
00549 //                                              break;
00550 //                                      case 8:
00551 //                                              for(int j = 0; j < bmpWidth; j++){
00552 //                                                      uint Color = *((uchar*) LinePtr);
00553 //                                                      m_BitmapData[Index].Red   = m_ColorTable[Color].Red;
00554 //                                                      m_BitmapData[Index].Green = m_ColorTable[Color].Green;
00555 //                                                      m_BitmapData[Index].Blue  = m_ColorTable[Color].Blue;
00556 //                                                      m_BitmapData[Index].Alpha = m_ColorTable[Color].Alpha;
00557 //                                                      Index++;
00558 //                                                      LinePtr++;
00559 //                                              }
00560 //                                              break;
00561 //                                      case 16:
00562 //                                              for(int j = 0; j < bmpWidth; j++){
00563 //                                                      uint Color = *((unsigned short int*) LinePtr);
00564 //                                                      m_BitmapData[Index].Red   = ((Color >> 10) & 0x1f) << 3;
00565 //                                                      m_BitmapData[Index].Green = ((Color >> 5) & 0x1f) << 3;
00566 //                                                      m_BitmapData[Index].Blue  = (Color & 0x1f) << 3;
00567 //                                                      m_BitmapData[Index].Alpha = 255;
00568 //                                                      Index++;
00569 //                                                      LinePtr += 2;
00570 //                                              }
00571 //                                              break;
00572 //                                      case 24:
00573 //                                              for(int j = 0; j < bmpWidth; j++){
00574 //                                                      uint Color = *((uint*) LinePtr);
00575 //                                                      m_BitmapData[Index].Blue  = Color & 0xff;
00576 //                                                      m_BitmapData[Index].Green = (Color >> 8) & 0xff;
00577 //                                                      m_BitmapData[Index].Red   = (Color >> 16) & 0xff;
00578 //                                                      m_BitmapData[Index].Alpha = 255;
00579 //                                                      Index++;
00580 //                                                      LinePtr += 3;
00581 //                                              }
00582 //                                              break;
00583 //                                      case 32:
00584 //                                              for(int j = 0; j < bmpWidth; j++){
00585 //                                                      uint Color = *((uint*) LinePtr);
00586 //                                                      m_BitmapData[Index].Blue  = Color & 0xff;
00587 //                                                      m_BitmapData[Index].Green = (Color >> 8) & 0xff;
00588 //                                                      m_BitmapData[Index].Red   = (Color >> 16) & 0xff;
00589 //                                                      m_BitmapData[Index].Alpha = Color >> 24;
00590 //                                                      Index++;
00591 //                                                      LinePtr += 4;
00592 //                                              }
00593 //                                              break;
00594 //                                      default:
00595 //                                              SAVEEXIT(false);
00596 //                              }
00597 //                      }
00598 //                      break;
00599 //              }
00600 //              // RLE 8
00601 //              case 1:{
00602 //                      uchar Count = 0;
00603 //                      uchar ColorIndex = 0;
00604 //                      int x = 0, y = 0;
00605 //
00606 //                      for(bool run = true; !feof(file) && run; ){
00607 //                              fread(&Count, 1, 1, file);
00608 //                              fread(&ColorIndex, 1, 1, file);
00609 //
00610 //                              if (Count > 0) {
00611 //                                      Index = x + y * bmpWidth;
00612 //                                      for (int k = 0; k < Count; k++) {
00613 //                                              m_BitmapData[Index + k].Red   = m_ColorTable[ColorIndex].Red;
00614 //                                              m_BitmapData[Index + k].Green = m_ColorTable[ColorIndex].Green;
00615 //                                              m_BitmapData[Index + k].Blue  = m_ColorTable[ColorIndex].Blue;
00616 //                                              m_BitmapData[Index + k].Alpha = m_ColorTable[ColorIndex].Alpha;
00617 //                                      }
00618 //                                      x += Count;
00619 //                              } else if (Count == 0) {
00620 //                                      int Flag = ColorIndex;
00621 //                                      switch(Flag){
00622 //                                              case 0: x = 0; y++; break;
00623 //                                              case 1: run = false; break;
00624 //                                              case 2:{
00625 //                                                      char rx = 0;
00626 //                                                      char ry = 0;
00627 //                                                      fread(&rx, 1, 1, file);
00628 //                                                      fread(&ry, 1, 1, file);
00629 //                                                      x += rx;
00630 //                                                      y += ry;
00631 //                                                      break;
00632 //                                              }
00633 //                                              default:{
00634 //                                                      Count = Flag;
00635 //                                                      Index = x + y * bmpWidth;
00636 //                                                      for(int k = 0; k < Count; k++){
00637 //                                                              fread(&ColorIndex, 1, 1, file);
00638 //                                                              m_BitmapData[Index + k].Red   = m_ColorTable[ColorIndex].Red;
00639 //                                                              m_BitmapData[Index + k].Green = m_ColorTable[ColorIndex].Green;
00640 //                                                              m_BitmapData[Index + k].Blue  = m_ColorTable[ColorIndex].Blue;
00641 //                                                              m_BitmapData[Index + k].Alpha = m_ColorTable[ColorIndex].Alpha;
00642 //                                                      }
00643 //                                                      x += Count;
00644 //                                                      if (ftell(file) & 1) fseek(file, 1, SEEK_CUR);
00645 //                                                      break;
00646 //                                              }
00647 //                                      }
00648 //                              }
00649 //                      }
00650 //                      break;
00651 //              }
00652 //              //case 2: // RLE 4 /* RLE 4 is not supported */
00653 //
00654 //              // BITFIELDS
00655 //              case 3:{
00656 //                      /* We assumes that mask of each color component can be in any order */
00657 //                      for(int i=0; i<bmpHeight; i++){
00658 //                              fread(Line, LineWidth, 1, file);
00659 //                              uchar *LinePtr = Line;
00660 //                              
00661 //                              for(int j=0; j < bmpWidth; j++){
00662 //                                      uint Color = 0;
00663 //
00664 //                                      if (m_BitmapHeader.BitCount == 16) {
00665 //                                              Color = *((unsigned short int*) LinePtr);
00666 //                                              LinePtr += 2;
00667 //                                      } else if (m_BitmapHeader.BitCount == 32) {
00668 //                                              Color = *((uint*) LinePtr);
00669 //                                              LinePtr += 4;
00670 //                                      }
00671 //                                      m_BitmapData[Index].Red   = ShiftRightByMask(Color, m_BitmapHeader.RedMask);
00672 //                                      m_BitmapData[Index].Green = ShiftRightByMask(Color, m_BitmapHeader.GreenMask);
00673 //                                      m_BitmapData[Index].Blue  = ShiftRightByMask(Color, m_BitmapHeader.BlueMask);
00674 //                                      m_BitmapData[Index].Alpha = ShiftRightByMask(Color, m_BitmapHeader.AlphaMask);
00675 //
00676 //                                      Index++;
00677 //                              }
00678 //                      }
00679 //                      break;
00680 //              }
00681 //              default:
00682 //                      SAVEEXIT(false);
00683 //      }
00684 //
00685 //      SAVEFREE(Line);
00686 //      fclose(file);
00687 //
00688 //      *outData = (Pixel*)m_BitmapData;
00689 //      return true;
00690 //      #undef SAVEEXIT
00691 //}

Generated on Fri Jun 18 2010 17:48:39 for Cannonball by  doxygen 1.7.0