Loading bitmap in C

Can someone please tell me how i can load a greyscale bitmap and use it for a heightmap.

Heres what i know:

  1. I can either ignore the header or use some of the information, like the width and height of the imgae
  2. If its greyscale i dont have to load rgb but can load just the r/g or b.
  3. I can use seek to go to different areas of the file

But i dont actually know how to do all this in C, can someone please either show me or point me to somewhere where i can see this working, please. Pref a tutorial or explanation of the code so i can write my own.

Cheers

Hi !

It depends, are you talking about a grayscale .BMP file or do you a bitmap in the OpenGL sense ?

There are lots of code and libraries to load different image formats into ram, www.wotsit.org has good descriptions of many file formats.

I think the NeHe tutorials has a .BMP loader if that might help to have a look at.

Mikael

Hi, this is the way i load bitmaps using Windows API and OpenGL.

1st step is to put the bmp you wanna load into the resources.

GLuint LoadTexFromMemory(int name) // should be somthing like IDB_BITMAP1
{
	HBITMAP bkg;
	BITMAP bmp;
	GLuint txtnumber;
	
	glGenTextures(1, &txtnumber);

	bkg = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(name), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);

	if (bkg)
	{
		GetObject(bkg, sizeof(bmp), &bmp);

		glPixelStorei(GL_UNPACK_ALIGNMENT,4);
		glBindTexture(GL_TEXTURE_2D, txtnumber);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // _MIPMAP_LINEAR
		gluBuild2DMipmaps(GL_TEXTURE_2D, 4, bmp.bmWidth, bmp.bmHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, bmp.bmBits);

		DeleteObject(bkg);

		return txtnumber;  
	}
	else 
		txtnumber = 0;

	return txtnumber;
}

Hope this help.

Steve.