Archived

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

crazyCelt

Problem copying bmp data

Recommended Posts

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;
		} 
		
	}
  

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites