title: How to load bmp into GLubyte array?
body: <p>All,</p>
  
  <p>I am trying to load up a bmp file into a GLubyte array (without using aux).</p>
  
  <p>It is unbelievable how what I thought would have been a trivial task is sucking up hours of my time.</p>
  
  <p>Can't seem to find anything on Google!</p>
  
  <p>This is what I hacked together but it's not quite working:</p>
  
  <pre><code>// load texture
  
  GLubyte *customTexture;
  
  string fileName("C:\\Development\\Visual Studio 2008\\Projects\\OpenGL_Test\\Crate.bmp");
  
  // Use LoadImage() to get the image loaded into a DIBSection
  HBITMAP hBitmap = (HBITMAP)LoadImage( NULL, (LPCTSTR)const_cast&lt;char*&gt;(fileName.c_str()), IMAGE_BITMAP, 0, 0, 
  LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );
  
  customTexture = new GLubyte[3*256*256]; // size should be the size of the .bmp file
  
  GetBitmapBits(hBitmap, 3*256*256, (LPVOID) customTexture);
  
  GetBitmapDimensionEx(hBitmap,&amp;szBitmap);
  </code></pre>
  
  <p>What happens is the call to LoadImage seems to be returning Undefined Value (NULL? I am not able to figure out if it's actually loading the bmp or not - a bit confused).</p>
  
  <p>At the moment I am converting bmps to raw then it's all easy.</p>
  
  <p>Anyone has any better and cleaner snippet?</p>