//////////////////////////////////////////////////////////
// //
// 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()
-Yoshi
XGXCX ''99
Edited by - YoshiN on December 17, 2001 11:12:23 PM
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
This what I can see for the time I have.
what is &image. ?
If you blit to off-screen surface, your immage will not become visible. You must blit into a primary surface (or back-buffer)
Mission 1 is complete we tought our children how to hate. Mission 2, the off switch does not work !!!
what is &image. ?
If you blit to off-screen surface, your immage will not become visible. You must blit into a primary surface (or back-buffer)
Mission 1 is complete we tought our children how to hate. Mission 2, the off switch does not work !!!
ℑ is the ddraw surface. I am blitting it to an offscreen surface, however, in the entire program which I uploaded to my server, it then blits that surface to the backbuffer, and then flips the surfaces.
Oh yeah, I have also included ddraw.lib and xguid.lib to the project, so it's not that.
-Yoshi
XGXCX ''99
Edited by - YoshiN on December 18, 2001 12:41:05 PM
Oh yeah, I have also included ddraw.lib and xguid.lib to the project, so it's not that.
-Yoshi
XGXCX ''99
Edited by - YoshiN on December 18, 2001 12:41:05 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement