Advertisement

Load a bitmap form file to a Direct Draw Surface

Started by February 08, 2000 08:44 AM
3 comments, last by xstreme2000 24 years, 10 months ago
Hiya I need help with loading a bitmap file to a direct draw surface. Before now I have always added my files to a resource script. Demo code would be idea...HELP ME!
The easiest way to do this is to use (or study) the file ddutil.cpp that comes with the DX SDK. You can find it in the samples/ddraw/src/ex# directories of the SDK directory. There''s a fuction in the file called DDLoadBitmap.

Advertisement
I know about this method but it only seem to load from the resource script not the file...if you can use it to load from a file could you show me how
ie: a line of code
The routines in ddutil.cpp can indeed be used to load it from a file (or resource). Look it up in the examples. If you dont like that approach, look up the bmp format somewhere (its pretty darn easy) and write your own loader.
// DXSurface is an already created directx surface
HBITMAP hbmp;
BITMAP bmp;
HDC SurfDC, BmpHdc;

hbmp = (HBITMAP)LoadImage(hInst, "bitmap.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE / LR_CREATEDIBSECTION);
if(hbmp==NULL)
return FALSE;
GetObject(hbmp, sizeof(BITMAP), &bm);
BmpHdc=CreateCompatibleDC(NULL);
SelectObject(BmpHdc, hbmp);

DXSurface->GetDC(&SurfDC);
BitBlt(BmpHdc, 0, 0, bm.bmWidth, bm.bmHeight, SurfDC, 0, 0, SRCCOPY);
DXSurface->ReleaseDC(SurfDC);
DeleteDC(BmpHdc);
DeleteObject(bmp);
DeleteObject(hbmp);

LR_LOADFROMFILE / LR_CREATEDIBSECTION, the slash should be a vertical line (shift+key above enter) this bb auto-converts it for some reason

Edited by - Funkymunky on 2/8/00 3:16:06 PM

This topic is closed to new replies.

Advertisement