I 'm making a game in C++ and I need some help, I want to display a bmp image. I want to read a a bmp file and save the color ids in a matrix. Could you please help me. :)

People have already done the work for you. The Direct3D extensions library (d3dx) has functions for loading bitmaps into Direct3D surfaces or textures. Unless you want to manually load the bitmap into your program as a learning experience, or if you just feel better doing things yourself, use Direct3D (or OpenGL if you're an open source kind of guy).

People have already done the work for you. The Direct3D extensions library (d3dx) has functions for loading bitmaps into Direct3D surfaces or textures. Unless you want to manually load the bitmap into your program as a learning experience, or if you just feel better doing things yourself, use Direct3D (or OpenGL if you're an open source kind of guy).

I kinda want to do it my self , no DirectX. I want some help like a piece of code to explain, something more explicit than the Wikipedia article.

I kinda want to do it my self , no DirectX. I want some help like a piece of code to explain, something more explicit than the Wikipedia article.

Download the source code for OpenGL and you will find the code you want. Otherwise that wiki article looks like it explains things pretty thoroughly. Doing what you want is a bit more difficult than writing a Hello World program, so expect it to be pretty complicated. Also look at some of the links given at the bottom of that article.

Start with a really simple BMP file (edit it using mspaint).

RRGG
RRGG
BBWW
BBWW

Where Red, Green, Blue and White pixels.
So you have a 4x4 pixel image, and not much else.

Then load it into an editor capable of showing you hex characters, then start reading the tutorials.

I have to mention that i use Borland 3.1 :D, it's quite old, but i use it very much, it supports pascal-like graphics. I also use Dev C++. I make the game in Borland 3.1. i would like a code for Borland 3.1, but its also ok a code for Dev.

i don't want to use OpenGL in dev !

i don't want to use OpenGL in dev !

Ancient Dragon said to look at the source for OpenGL (one of the nice things about having an open source graphics API) - not to actually use it. But I think that would be a bit complicated. I certainly wouldn't feel confident looking through the source for OpenGL trying to find code for a bitmap loader. Then again, I'm not sure how easy it would be to find a tutorial for a bitmap loader.

is this thread helpful ? http://www.daniweb.com/forums/thread17496.html
i tried this one

one easy way to do it is,

declare image and header array;

unsigned char Header[0x435],image[256][256];

and to read image;

fread(Header,1,0x435,fp);	// copy image header to Header array
		fseek(fp,0x436,SEEK_SET);	// Move file pointer to start of image data
		fread(image,1,256*256,fp);	// read image data and copy to ImageIn1[][] array

		fclose(fp);

all i got were negative values.
could it work ?

well if you are using openGL for your game programming then its my little code will helps you alot in loading bitmap images using glut library..
best of luck..

here is one that I use sometimes. Note that this does not work for every
bitmap images.

int LoadBitmap( wchar_t* filename)
{
   GLubyte* pixels;
   HBITMAP hbmp;  
   BITMAP bmp; 
   GLuint size;
   GLenum format;
   GLuint totalBytes;

   texID++;

   hbmp=(HBITMAP)LoadImage(GetModuleHandle(NULL), filename, 
                IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION |  
                LR_LOADFROMFILE );

   if(hbmp==NULL)
   {
	   MessageBox(NULL,L"ERROR : CANNOT LOAD FILE!",L"IMAGE LOADING",MB_OK);
	   return -1;
   }

   GetObject(hbmp,sizeof(bmp), &bmp);  				   		 
 
   size = bmp.bmHeight*bmp.bmWidthBytes;
   
   totalBytes = bmp.bmBitsPixel/8;

   switch(bmp.bmBitsPixel)
   {
		case 1:
		case 4: 
		case 8:
			format = GL_LUMINANCE;			
			break;

		case 24:
			format = GL_RGB;
			break;

		case 32:
			format = GL_RGBA;
			break;
   }

   pixels = new GLubyte[size];

   memcpy(pixels,bmp.bmBits,size);

//Now use data. I used this for openGL but deleted that stuff
// because of it not begin relevent.

	

//After doing something with the data delete object.
   DeleteObject(hbmp);   

   delete [] pixels;

   return  true;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.