DirectDraw 7 and 8-bit .BMPs

Started by
3 comments, last by crunchlet 21 years, 3 months ago
Hi all, I''m having some trouble loading .BMP files onto my DirectDraw surfaces. I pretty much copied the example 8-bit .BMP code in Andre LaMothe''s TOTWGPG. Basically the code reads in the BITMAPFILEHEADER, BITMAPINFOHEADER & palette, then allocates a memory buffer for the actual image and reads it in. I use the biWidth and biHeight attributes to determine the size of the image (using biSizeImage as in the example code causes the program to crash). Next the program is supposed to copy the image data from the buffer to the DD7 primary surface using memcpy. The code compiles OK, and executes without crashing, but instead of displaying the bitmap I just get a blank screen and the cursor. I feel kind of stupid getting stuck on something this basic.. Any help would be muchly appreciated. Thanks
Advertisement
i haven''t read that tutorial, but i think it''s about writing your own bmp file loader. If so, who not use the LoadBitmap() supplied with GDI?

The past was unknown, the future was predicted.
the future is just like the past, just later. - TANSTAAFL
Look for other bitmap loading routines online. What I have found with all the books I have, WGPFD, TOTWGPG (Almost same book!), and Jim Adams'' PRPGWDX and Sams TYDX7 in 24, is that the code they contain is not always that good when simply copied. I either mix and match code from the books or I look thoroughly at the example code to see if I am missing something.
are you back buffering? if so, you have to copy the bitmap to the backbuffer, then flip it.

post some code.
Programmers of the world, UNTIE!
quote:Original post by MattS423
are you back buffering? if so, you have to copy the bitmap to the backbuffer, then flip it.


OK, it works now. Thanks muchly!

Here's the code, if you're interested:


  int fnLoadBitmap(BITMAP_FILE_PTR bitmap, char *fileName) {	int hFile,			// file handle		index,			// counter		tempColor,		// temp color entry		offset,			// file offset in bytes (where the actual image file starts)		size;			// file size	OFSTRUCT fileData;	// the file data information	// open the file if it exists	if ((hFile = OpenFile(fileName, &fileData, OF_READ)) == -1)		return(0);	// now load the bitmap file header	_lread(hFile, &bitmap->BitmapFileHeader, sizeof(BITMAPFILEHEADER));	// test if this is a bitmap file	if (bitmap->BitmapFileHeader.bfType != BITMAP_ID) {		// close the file		_lclose(hFile);		// return error		return(0);	} // end if	// now we know it's a bitmap, read in all the sections	// read the bitmap info header	_lread(hFile, &bitmap->BitmapInfoHeader, sizeof(BITMAPINFOHEADER));	// load the color palette if there is one	if(bitmap->BitmapInfoHeader.biBitCount == 8) {		_lread(hFile, &bitmap->palette, MAX_COLORS_PALETTE*sizeof(PALETTEENTRY));		// set all the flags in the palette correctly		// and fix the reversed BGR RGBQUAD data format			for(index=0; index < MAX_COLORS_PALETTE; index++) {			// reverse the red and blue fields			tempColor						= bitmap->palette[index].peRed;			bitmap->palette[index].peRed	= bitmap->palette[index].peBlue;			bitmap->palette[index].peBlue	= tempColor;			// always set the flags word to this			bitmap->palette[index].peFlags	= PC_NOCOLLAPSE;		} // end for(index)	} // end if	// read the image data	size = (int)(bitmap->BitmapInfoHeader.biWidth * bitmap->BitmapInfoHeader.biHeight); 	//size = (int)bitmap->BitmapInfoHeader.biSizeImage;	_lseek(hFile, -(int)(size), SEEK_SET);	// read the image	if (bitmap->BitmapInfoHeader.biBitCount == 8 || 		bitmap->BitmapInfoHeader.biBitCount == 16 || 		bitmap->BitmapInfoHeader.biBitCount == 24) {		// delete the last image if there was one		if (bitmap->buffer)			free(bitmap->buffer);		// allocate memory for the image		if (!(bitmap->buffer = (UCHAR *)malloc(size))) {			// close the file			_lclose(hFile);			// return error			return(0);		} // end if		// now read it in		_lread(hFile, bitmap->buffer, size);	} else {		// close the file		_lclose(hFile);		// return error		return(0);	} // end if	// close the file	_lclose(hFile);	// flip the bitmap	fnFlipBitmap(bitmap->buffer, 		bitmap->BitmapInfoHeader.biWidth*(bitmap->BitmapInfoHeader.biBitCount/8), 		bitmap->BitmapInfoHeader.biHeight);	// return success	return(1);} // end fnLoadBitmap()   


and to copy it to the back buffer:


  // lock the display surface	if (FAILED(lpddSBack->Lock(NULL, &ddSD, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL)))		return(0);	// make copy of source and destination addresses	UCHAR *ptrSrc	= g_bitmap.buffer;	UCHAR *ptrDest	= (UCHAR *)ddSD.lpSurface;;			// copy line by line	for (int y = 0; y < SCREEN_HEIGHT; y++) {		// copy line		memcpy((void *)ptrDest, (const void *)ptrSrc, SCREEN_WIDTH);		// advance pointers to next line		ptrDest += ddSD.lPitch;		ptrSrc	+= SCREEN_WIDTH;	} // end for y	// unlock surface	if (FAILED(lpddSBack->Unlock(NULL)))		return(0);   






[edited by - crunchlet on January 3, 2003 11:10:24 PM]

This topic is closed to new replies.

Advertisement