Jump to content
  • Advertisement

Archived

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

theObserver

Can anyone spot the mistake in this code?

This topic is 5607 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 created a c++ class for a directdraw project called Bitmap.But I am having trouble with this one meathod. Its purpose is so copy the bitmap onto an already created directdraw surface. 'Data' points to the actual bitmap data which is stored in the class. The thing is, it works fine when the Pitch == Bitmapwidth. When it doesnt, the bitmap is displayed wrong.
BOOL cBitmap::BitmapToSurface(LPDIRECTDRAWSURFACE7 lpddSurface,int ImageX, int ImageY)
{
  DDSURFACEDESC2 ddsd;
  UCHAR *Source;
  UCHAR *Dest;

	if (!Data || !lpddSurface)
	  return false;
	
	memset(&ddsd,0,sizeof(ddsd));
	ddsd.dwSize = sizeof(ddsd);

	if (FAILED(lpddSurface->Lock(NULL,&ddsd,DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,NULL)))
		return false;

	Source = Data + ImageX + (ImageY * BitmapWidth);
	Dest = (UCHAR *) ddsd.lpSurface;

	for (int Counter =0;Counter < BitmapHeight;Counter++){
		memcpy(Dest,Source,BitmapWidth);
		Dest += ddsd.lPitch;
		Source += BitmapWidth;
	}

	lpddSurface->Unlock(NULL);
	return true;
}

[edited by - theObserver on August 7, 2003 3:01:22 PM]

Share this post


Link to post
Share on other sites
Advertisement
You should jump the lPitch amount between each scanlines.
As ddraw docs tell you, the pitch isn''t necessarily the width*bitdepth/8 as you might assume. However, it is, in bytes, the memory width of a scanline (which could include some buffer space).

Share this post


Link to post
Share on other sites
Doesnt the lpitch property from DDSURFACEDESC2 return the actual pitch of the surface (including any buffer)? My understanding was that once I locked the surface, I could use now valid lpitch from the DDSURFACEDESC2 to safely advance the scanline taking into account buffering etc.

Share this post


Link to post
Share on other sites
if you are trying to copy a bitmap onto another surface, why dont you use DirectDraw''s blt function or FastBlt. for one, it has to be faster than any method you are using. and two, it does it correctly!

Share this post


Link to post
Share on other sites
quote:
Original post by theObserver
Doesnt the lpitch property from DDSURFACEDESC2 return the actual pitch of the surface (including any buffer)? My understanding was that once I locked the surface, I could use now valid lpitch from the DDSURFACEDESC2 to safely advance the scanline taking into account buffering etc.


You''re right.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!