Jump to content
  • Advertisement

Archived

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

julienX

Copying bitmap to ddraw surface HELP

This topic is 5637 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''m new to directdraw and am currently writing a bitmap loader. So far I have correctly loaded the bitmap data (bitmap file header, bitmap info header, palette etc....) from the bitmap file, and I have created an offscreen directdraw surface to store the bitmap. But my problem is, I have absolutely no idea of how to copy the bitmap data onto the ddraw surface. Any help?? My bitmap data is stored in a UCHAR pointer. I have all the neccesary details of the bitmap, but please could someone give me some advice on copying the bitmap to a surface? Thanks for your time

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
There are tutorials in the Articles section here on how to transfer bitmaps to directdraw surfaces.


  
LPDIRECTDRAWSURFACE7 cGraphics::LoadBMPSurface(LPCSTR lpFilename)
{
HDC hDC;
HBITMAP bit;
BITMAP bitmap;
LPDIRECTDRAWSURFACE7 surf;

bit = (HBITMAP) LoadImage(NULL,lpFilename,IMAGE_BITMAP,0,0,LR_DEFAULTSIZE | LR_LOADFROMFILE);

if(!bit)
{
return(NULL); //Error trapping

}

GetObject(bit,sizeof(BITMAP),&bitmap);

surf = CreateNewSurface(bitmap.bmWidth,bitmap.bmHeight);

if(surf == NULL)
{
DeleteObject(bit);
return(NULL); //More error trapping

}
else
{
surf->GetDC(&hDC);

HDC bit_dc = CreateCompatibleDC(hDC);

//Blit the interface to the surface


SelectObject(bit_dc,bit);

BitBlt(hDC,0,0,bitmap.bmWidth,bitmap.bmHeight,bit_dc,0,0,SRCCOPY);

surf->ReleaseDC(hDC);

DeleteDC(bit_dc);
}

DeleteObject(bit);

return(surf);
}


This is taken from Teach Yourself DirectX7 in 24 hours. CreateNewSurface is my own function, it basically creates and returns a surface onto which the bitmap should load. You will get the idea

Share this post


Link to post
Share on other sites
The answer above could solve the problem.I have some similar code which could help you!

//***************************************************************
//Function:DDLoadBitmap( )
//Note:Load Bitmap onto DirectDraw Surface
//***************************************************************
IDirectDrawSurface* CGame::DDLoadBitmap(IDirectDraw *lpDD,LPCSTR sFileName)
{
HBITMAP hbm; BITMAP bm;
DDSURFACEDESC ddsd; IDirectDrawSurface *lpDDS;
HDC hdcImage,hdc;

hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL),sFileName,
IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);

if(hbm==NULL)
hbm = (HBITMAP)LoadImage(NULL,sFileName,IMAGE_BITMAP,0,0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);

if(hbm==NULL) return FALSE;

if(GetObject(hbm,sizeof(bm),&bm)==0) return FALSE;

//Initial Surface
ZeroMemory(&ddsd,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN|DDSCAPS_SYSTEMMEMORY;
ddsd.dwWidth = bm.bmWidth;
ddsd.dwHeight = bm.bmHeight;
if(lpDD->CreateSurface(&ddsd,&lpDDS,NULL)!=DD_OK) return FALSE;

if(!(hdcImage = CreateCompatibleDC(NULL)) ) return FALSE;
SelectObject(hdcImage,hbm);

if((lpDDS->GetDC(&hdc))!=DD_OK) return FALSE;

StretchBlt(hdc,0,0,bm.bmWidth,bm.bmHeight,hdcImage,
0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);

lpDDS->ReleaseDC(hdc);

DeleteObject(hbm);

DeleteDC(hdcImage);

return lpDDS;
}

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!