Loading Bitmap into GLubyte Array

Please could someone show me or provide me with the source code to load a bitmap into a GLubyte Array

So the actual bitmap image is in GLubyte[] , so I can edited it .

I am trying to make a game with destructable terrain which can be loaded from bitmaps :) . Any other hints on how to edit it in realtime , would be useful .

Ps. as you obviously have worked out I am using OpenGL .

Lots of thanks in advance,

Paladin
LVL 1
Paladin_VBAsked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
>> How do i find the value which should be put in MAX_SIZE

That would be the size of the bitmap, e.g.

#include <sys/types.h>
#include <sys/stat.h>

struct _stat st;

_stat("c:\\tmp\\myfile.bmp",&st);

DWORD dwSize = st.st_size;

  // Use LoadImage() to get the image loaded into a DIBSection
  HBITMAP hBitmap = (HBITMAP)LoadImage( NULL, szFileName, IMAGE_BITMAP, 0, 0,
              LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );

 GLubyte* ab = new GLubyte[dwSize]; // size should be the size of the .bmp file

 GetBitmapBits(hBitmap,dwSize, (LPVOID) ab);

 SIZE szBitmap; // has 'cx' and 'cy'

 GetBitmapDimensionEx(hBitmap,&szBitmap);
0
 
jkrCommented:
Check out http://support.microsoft.com/default.aspx?scid=kb;en-us;158898 ("HOWTO: How To Use LoadImage() to Read a BMP File"). The idea is to

  // Use LoadImage() to get the image loaded into a DIBSection
   HBITMAP hBitmap = (HBITMAP)LoadImage( NULL, szFileName, IMAGE_BITMAP, 0, 0,
               LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );

  GLubyte ab [MAX_SIZE]; // size should be the size of the .bmp file

  GetBitmapBits(hBitmap,MAX_SIZE, (LPVOID) ab);
0
 
Paladin_VBAuthor Commented:
So how do i find the size of the bitmap ?

point boost 25 :P
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
jkrCommented:
Oh, that's easy, e.g.

#include <sys/types.h>
#include <sys/stat.h>

struct _stat st;

_stat("c:\\tmp\\myfile.bmp",&st);

DWORD dwSize = st.st_size;
0
 
Paladin_VBAuthor Commented:
Wowh that was fast !!!! Thanks :)
0
 
Paladin_VBAuthor Commented:
How do i find the value which should be put in MAX_SIZE ? and how do i find the dimensions of the bitmap ??

+20 :P
0
All Courses

From novice to tech pro — start learning today.