Jump to content
  • Advertisement


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


Problem copying bmp data

This topic is 6234 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

	{	// 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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!