Original Post
Can anyone tell me if there is anything wrong with this function? The bitmap never shows up on the surface. You can download the entire cpp file here. All this file is supposed to do is load a 128x128 bitmap of a penguin onto the test surface, blit the test surface to the back buffer, and then flip the primary surface with the backbuffer. The image however, never loads, and I don't know why. Please help me as this has been screwing with my head, and I must figure out why it's not working.
Thanks,
Niki
-Yoshi
XGXCX ''99
Edited by - YoshiN on December 17, 2001 11:12:23 PM
//////////////////////////////////////////////////////////
// //
// Loads a bitmap file into the surface //
// 'image' from a file with the name //
// 'fname' which is 'width' and 'height' //
// in dimension. //
// //
int Load_Bitmap(LPDIRECTDRAWSURFACE7 image, //
char *fname, //
int width, int height)/////////
{
DDSURFACEDESC2 ddsd; // ddraw surface description
HDC hdc, hdcimage; // device context of the surface and image
BITMAP bitmap; // bitmap object
HBITMAP hbitmap; // handle to the bitmap
// clear the ddsd struct of garbage
memset(&ddsd, 0, sizeof(ddsd));
// fill in the description structure
ddsd.dwSize = sizeof(ddsd); // size of the struct
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; // flags
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; // surface is off screen
ddsd.dwWidth = width; // width of surface
ddsd.dwHeight = height; // height of surface
// create the surface
if(lpdd->CreateSurface(&ddsd, ℑ, NULL)!=DD_OK)
return(0);
// load the bitmap and get the object
hbitmap = (HBITMAP)LoadImage(NULL, fname, IMAGE_BITMAP, width, height,
LR_LOADFROMFILE);
hdcimage = CreateCompatibleDC(NULL);
SelectObject(hdcimage, hbitmap);
GetObject(hbitmap, sizeof(BITMAP), &bitmap);
// copy the bitmap to the surface
image->GetDC(&hdc);
BitBlt(hdc, 0, 0, width, height, hdcimage, 0, 0, SRCCOPY);
// release the device context and destroy the image device context
image->ReleaseDC(hdc);
DeleteDC(hdcimage);
return(1);
} // end Load_Image()
|