Skip to main content
gamedev.net
🔒 Locked

the mysterious DDLoadBitmap function

Started by serratemplar 2 replies 1.3k views
Original Post
serratemplar
serratemplar
Alright; I''m trying to get back into programming and game programming (it''s been a couple of years) and I''m warming back up to DirectX by trying to write a 2D game. This means I''m using DirectDraw from DirectX7; please don''t tell me it''s obsolete, cause I know that. What I want to know is this: How do I load a 32bit bitmap? My old code uses this function call... g_lpddsBackground = DDLoadBitmap(g_lpdd, "background1.bmp", SCREEN_RESOLUTION_X, SCREEN_RESOLUTION_Y); I can''t find DDLoadBitmap documented anywhere in the DirectX archives, DX9 help files, anywhere on msdn.microsoft.com, no where. And so I tried to look into loading it myself but all I can find in Lamothe''s books (old and new), and online here at gamedev.net is a number of methods that all load 16bit bitmaps into a surface. That''s nice, but what if I want 32bit? I guess then I have 2 questions: 1) Is loading a 32bit bitmap a simple change in the methods I''ve read about? Or is it awesome and mysterious and beyond my powers? 2) Should I just use 16bit bmp''s so people who have poor graphics cards or monitors can play my game? As it is I may just go with 16bits so I can load them myself and know what''s going on (though DDLoadBMP compiles right now, I don''t know *what* library it''s in and since I can''t find it, I feel I can''t count on it). As always, I really appreciate the input of everyone here. This is the best forum of any forum ever.
Sailorstick
Sailorstick
I use the API LoadImage and then blit that HDC onto a surface.
Code to load image onto a HDC:

HPIC DXGraphics::LoadPicture(const char* filename, COLORREF colourkey){
HDC tempDC;
HBITMAP tempHBmp;
BITMAP tempBmp;
DXPicture* tempPic = NULL;

tempDC = CreateCompatibleDC(NULL);
tempHBmp = (HBITMAP)LoadImage(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_SHARED|LR_CREATEDIBSECTION|LR_DEFAULTSIZE);
if(tempHBmp){
if(!SelectObject(tempDC, tempHBmp)){
DBG1(WriteErr("DXPicture.LoadBitmap", "LoadImage", "Error Loading Bitmap"));
}else{
GetObject(tempHBmp, sizeof(tempBmp), &tempBmp);
tempPic = new DXPicture(m_Scr->GetDirectDraw(), tempBmp.bmWidth, tempBmp.bmHeight, colourkey);
if(tempPic){
if(!tempPic->BlitHDC(tempDC, 0, 0, tempBmp.bmWidth, tempBmp.bmHeight)){
DBG1(WriteErr("DXGraphics.CreatePictureFromDC", "pic->BlitHDC", "FAILED"));
SAFE_DELETE(tempPic);
DeleteDC(tempDC);
return NULL;
}

DeleteDC(tempDC);
return AddPicture(tempPic, filename, PD_TAIL, 0);
}
}
}
DeleteDC(tempDC);
return NULL;
}

Relevant snippets of code from my DXPicture class to blit the HDC onto the surface:
DXPicture::DXPicture(LPDIRECTDRAW7 DirectDraw, int width, int height, COLORREF colourkey){
DDSURFACEDESC2 SurfaceDescription;
HRESULT res;
m_intWidth = width;
m_intHeight = height;
ZeroMemory(&SurfaceDescription, sizeof(SurfaceDescription));
SurfaceDescription.dwSize = sizeof(SurfaceDescription);
SurfaceDescription.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
SurfaceDescription.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; // | DDSCAPS_VIDEOMEMORY;

SurfaceDescription.dwWidth = m_intWidth;
SurfaceDescription.dwHeight = m_intHeight;
if(colourkey && Scr){
SurfaceDescription.dwFlags |= DDSD_CKSRCBLT;
SurfaceDescription.ddckCKSrcBlt.dwColorSpaceLowValue = Scr->ConvertGDIColour(colourkey);
SurfaceDescription.ddckCKSrcBlt.dwColorSpaceHighValue = Scr->ConvertGDIColour(colourkey);
}
res = DirectDraw->CreateSurface(&SurfaceDescription, &m_PicBuffer, NULL);
if(FAILED(res)){
MessageBox(NULL, DXGetErrorString9A(res), "CREATE PIC BUFFER ERROR", 0);
m_PicBuffer = NULL;
}
}


DXPicture::~DXPicture(){
SAFE_RELEASE(m_PicBuffer);
}


bool DXPicture::BlitHDC(HDC hDC, int srcx, int srcy, int srcw, int srch){
HDC picDC;
if(m_PicBuffer){
m_PicBuffer->GetDC(&picDC);
BitBlt(picDC, 0, 0, srcw, srch, hDC, srcx, srcy, SRCCOPY);
m_PicBuffer->ReleaseDC(picDC);
return true;
}
return false;
}[source]
serratemplar
serratemplar
I''m sorry, I was unclear.

I''m using Visual C++. I''m only finding the method you suggest as a Visual Basic function? Which I don''t think will work for me. =)

So I am still stumped!
eFoDay
eFoDay
check out this files

C:\DX90SDK\Samples\C++\Common\ddutil.h
C:\DX90SDK\Samples\C++\Common\ddutil.cpp

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.