Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Shadow1234567890

can someone check this for errors? Doesn't load a bitmap

This topic is 5680 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

First of all I know that in order to correctly display this bitmap I would have to switch the r and b values in the load bitmap function. It should at least be drawing something, and I wonder what I am doing wrong.
  
#include "Main.h"

byte * LoadBMP(char * filename, BITMAPINFOHEADER *bih) {
	byte * imageData;	//THIS WILL END UP BEING OUR IMAGE READ FROM THE FILE

	ifstream fin(filename, ios::in | ios::binary | ios::nocreate);	//OPEN FILE

	if(fin.fail())
             return NULL;                                       
	fin.seekg(0, ios::end);
	long filesize = fin.tellg();
	fin.seekg(0, ios::beg);
	byte * buffer = new byte[filesize];  //ALLOCATE TEMPORARY BUFFER

	fin.read(buffer, filesize);
	fin.close();
	const byte * ptr = buffer;	//CREATE POINTER TO BUFFER TO EXTRACT STUFF FROM THE FILE

	BITMAPFILEHEADER * pHeader = (BITMAPFILEHEADER*)ptr;	//EXTRACT THE BITMAPFILEHEADER TO CHECK TYPE

	ptr += sizeof(BITMAPFILEHEADER);	//GO PAST BITMAPFILEHEADER IN FILE

	if(pHeader->bfType != BITMAP_ID) {	//CHECK THE TYPE, DEFINED IN MAIN.H

		MessageBox(NULL, "BITMAP ID INVALID", "BITMAP ID INVALID", MB_OK);
		return NULL;
	}
	bih = (BITMAPINFOHEADER*) ptr;	//EXTRACT OUR BITMAPINFOHEADER

	ptr += sizeof(BITMAPINFOHEADER);

	imageData = new byte[bih->biSizeImage];
	imageData = (byte*)ptr;	//EXTRACT ALL OF THE INFORMATION FOR THE IMAGE

	
	return imageData;	//RETURN IT

}

void DrawBMP() {
	byte * bitmap;
	BITMAPINFOHEADER bih;
	bitmap = LoadBMP("bitmap.bmp", &bih);
	glRasterPos2i(100, 100);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);	//SET MEMORY ALIGNMENT

	
	glDrawPixels(bih.biWidth, bih.biHeight, GL_RGB, GL_UNSIGNED_BYTE, bitmap);
}
  

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!