Jump to content
  • Advertisement

Archived

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

omegasyphon

surface question

This topic is 6582 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

this probably has been asked before but i have a surface of size 640x480 called lpdd1 now how do would i copy say a bitmap from lpdd1 the size of 64x64 onto surface2?

Share this post


Link to post
Share on other sites
Advertisement
Well your not copying a bitmap, simply the pixels. You can do this using a standard blit operation. Do you want to copy only a 64x64 section of surface one or "shrink" the image down to surface2 which is 64x64? In either case setup source and destination RECT structures. Then make your call such as surface2->Blt(&DestRect,lpdd1,&SrcRect, DDBLT_WAIT, NULL);

Share this post


Link to post
Share on other sites
This took me awhile too!

LPDIRECTDRAWSURFACE7 BitmapSurface(LPCTSTR filename, LPDIRECTDRAW7 lpLocalDD)
{
HDC hdc;
HBITMAP hbitmap;
LPDIRECTDRAWSURFACE7 surface;

//Load image to handle
hbitmap = (HBITMAP)LoadImage(NULL, filename, IMAGE_BITMAP, 0, 0,
LR_DEFAULTSIZE | LR_LOADFROMFILE);
//If fail return Null
if (!hbitmap)
{
return(NULL);
}//end if

//Get the bitmap''s size
BITMAP bitmap;
GetObject(hbitmap, sizeof(bitmap), &bitmap);
int surfwidth = bitmap.bmWidth;
int surfheight = bitmap.bmHeight;

HRESULT ddrval;

//Setup surface for creation
DDSURFACEDESC2 ddsd;
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
ddsd.dwWidth = surfwidth;
ddsd.dwHeight = surfheight;

ddrval = lpLocalDD->CreateSurface(&ddsd, &surface, NULL);

//If failed, clean up and return Null
if (ddrval != DD_OK)
{
DeleteObject(hbitmap);
return(NULL);
}
//Bit the temp DC to the surface''s dc and return the surface
else
{
surface->GetDC(&hdc);
HDC bitDC = CreateCompatibleDC(hdc);
SelectObject(bitDC, hbitmap);
BitBlt(hdc, 0, 0, surfwidth, surfheight, bitDC, 0, 0, SRCCOPY);
surface->ReleaseDC(hdc);
DeleteDC(bitDC);
}//end if

DeleteObject(hbitmap);

//Return success
return(surface);
}

//I assume DirectDraw7 is already setup and is lpDD
LPDIRECTDRAWSURFACE7 lpdd1;
lpdd1 = CreateBitmapSurface("bitmapfile.bmp", lpDD);

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!