Problem copying bmp data

Started by
0 comments, last by crazyCelt 22 years, 9 months ago
I have a problem with the following piece of code that copies a bitmap''s data to a Direct Draw structure''s lpSurface.It seems the program exits on the 361st iteration of the for loop and I can''t figure out why.SCREENHEIGHT and SCREENWIDTH are consts for the resolution, which is 800 x 600.If it makes any difference, this code is from Andre LaMothe''s Tricks of the Windows Game Programming Gurus.
  
UCHAR *imageBuffer = (UCHAR *)ddsd.lpSurface;       
	
	
	// test if memory is linear

	if (ddsd.lPitch == SCREENWIDTH)
	{
		// copy memory from double buffer to primary buffer

		memcpy((void *)imageBuffer, (void *)bitmap->buffer, SCREENWIDTH*SCREENHEIGHT);
		
	} // end if

	else
	{	// non-linear

		
		// make copy of source and destination addresses

		UCHAR *pDest = imageBuffer;
		UCHAR *pSrc  = bitmap->buffer;
		
		// memory is non-linear, copy line by line

		for (int y=0; y < SCREENHEIGHT; y++)
		{
			// copy line

			memcpy((void *)pDest, (void *)pSrc, SCREENWIDTH);
			
			// advance pointers to next line

			pDest   += ddsd.lPitch;
			pSrc    += SCREENWIDTH;
		} 
		
	}
  
Advertisement
Looks ok to me, check your SCREEN variables, and make sure you account for multiple byte pixels. 16Bit=2, 24Bit=3, 32Bit=4.

You could always use the DDCopyBitmap routine in the file ddutils.c from the DX SDK, it even loads a BMP file for you.

  Game Download  ZeroOne Realm

  Downloads:  ZeroOne Realm

This topic is closed to new replies.

Advertisement