Original Post
I really don''t know what''s wrong with my code, I''m getting very frustrated with directx. OpenGL is so easy to use compared to directx its almost funny. But for some reason I want to continue torturing myself by trying to learn it. My "LoadBitmap" function is below, please help:
/////////////////////////////////////////////////////////////////
//
// Func: LoadBitmap
// Desc: loads bitmap from file
//
/////////////////////////////////////////////////////////////////
IDirectDrawSurface7 *LoadBitmap()
{
HBITMAP hbm = NULL;
BITMAP bm;
HDC hdcImage = NULL;
HDC hdc = NULL;
DDSURFACEDESC2 ddsd;
IDirectDrawSurface7 *pdds;
//
// Try to load the bitmap as a file
//
hbm = (HBITMAP) LoadImage(NULL, "test.bmp", IMAGE_BITMAP, 0,
0,LR_LOADFROMFILE);
if(hbm == NULL)
{
MessageBox(NULL,"Loading Image Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}
//
// Get size of the bitmap
//
GetObject(hbm, sizeof(bm), &bm);
//
// Create a DirectDrawSurface for this bitmap
//
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwWidth = bm.bmWidth;
ddsd.dwHeight = bm.bmHeight;
if (DirectDraw7->CreateSurface(&ddsd, &pdds, NULL) != DD_OK)
{
// Failed
return NULL;
}
//
// Select bitmap into a memoryDC so it can be used
//
hdcImage = CreateCompatibleDC(NULL);
if (pdds->GetDC(&hdc) == DD_OK)
{
BitBlt(hdc, 0, 0, ddsd.dwWidth, ddsd.dwHeight, hdcImage, 0, 0, SRCCOPY);
pdds->ReleaseDC(hdc);
}
DeleteObject(hbm);
DeleteDC(hdcImage);
return pdds;
}