Archived

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

Shadow1234567890

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

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