Advertisement

bmp to screen

Started by September 27, 2002 02:13 PM
1 comment, last by steve1992 22 years, 1 month ago
how do i load a bitmap image to buffer then screen directx8 C++
There's this great thing called a "search engine" that can often answer your questions! If that fails you, you could always look in the selection of articles available here for info on DirectX.

Since I'm feeling helpful today,

Here if you don't care to use ID3DXSprite, or here if you do want to use it (and have a Gamasutra membership).



[edited by - micepick on September 27, 2002 3:58:58 PM]
Advertisement
My beautiful texture manager, supporting various API's has routines for manipulating various image formats such as 24bit bitmaps. Following this is a code listing. However, I highly suggest you learn to use search engines and utilize site's such as gamedev's articles.

/* Please forgive me, if the bitmap related code has possible bugs, none have been detected yet; as I have been using other formats, previously and have just added support for BMP's. */


        bool CTexture::LoadBitmapFile(char *strName, unsigned int uiWidth, unsigned int uiHeight){		FILE		   *pFile;	SBMPFileHeader fileHeader;	SBMPInfoHeader infoHeader;	// open file - "rb"	pFile = fopen(strName, "rb");	if (!pFile)	{		assert(pFile);	//	return false;	}	// file header	fread(&fileHeader, sizeof(SBMPFileHeader), 1, pFile);	// check bmp validity	if (fileHeader.usType != 0x4D42)	{		assert(pFile);		fclose(pFile);		return false;	}	// info header	fread(&infoHeader, sizeof(SBMPInfoHeader), 1, pFile);	// beginning of data	fseek(pFile, fileHeader.ulOffBits, SEEK_SET);	// data allocation			m_pData = new unsigned char[infoHeader.ulSizeImage];	// read data	fread(m_pData, 1, infoHeader.ulSizeImage, pFile);	if (!m_pData)	{		assert(m_pData);		delete [] m_pData;		fclose(pFile);		return false;	}	// swap r and b values to get rgb since bitmap color format is bgr	for (int i = 0; i < infoHeader.ulSizeImage; i+=3)	{		unsigned char temp = m_pData[i];							 m_pData[i]   = m_pData[i+2];							 m_pData[i+2] = temp;	}	// copy to CImage class members	m_uiWidth = uiWidth;	m_uiHeight = uiHeight;	fclose(pFile);	// create texture	CreateDefTex();		// build texture mipmap/s	EnableMipMaps();	if (m_pData)	{		delete [] m_pData;		m_pData = 0;	}	return true;}        



[edited by - masterg on September 27, 2002 12:40:15 AM]
masterghttp:/masterg.andyc.org

This topic is closed to new replies.

Advertisement