• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

## Recommended Posts

I have been having the hardest time trying to load a bitmap and display it on the screen using the GDI. I just want to load the bitmap and create an offscreen surface in my game initialization. Then In my game loop, I want to call GetDC() on my offscreen surface, then load my bitmap into a memory dc, copy that to the other dc (the offscreen surface), then use Blt to copy the offscreen surface to my back surface. I''ve seen this before on gamedev, but it always has something to do with someone''s own engine, but I just want some code for my initialization and main game loop that will do this. If anyone can show me some sample code for this, I would be very thankful. ~Andrew Clark

##### Share on other sites
whoa man, ive been bugging this forum for too long
about the same subject, so i guess its my time to help:

1. you want your game loop to be as fast a possible,
PRE LOAD all bitmaps to the off screen surfaces.

2. dont use getDC to copy from the off screen surface
to the back surface. instead, use the surface blitter.
much more faster. (ALOT FASTER )

3. u wanted code? sure:

  //// here we load the bitmap HBITMAP bitmap; IDirectDrawSurface *TheSprite; bitmap = (HBITMAP) LoadImage(NULL, Bitmap_Filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE); BITMAP bm; GetObject( bitmap, sizeof( bm ), &bm ); int width = bm.bmWidth; int height = bm.bmHeight; ////create the surface DDSURFACEDESC ddsd; memset(&ddsd,0,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwHeight = height; ddsd.dwWidth = width; lpDD->CreateSurface(&ddsd, &TheSprite, NULL);////now, move the bitmap to the off screen surface we just created HDC hDCImage; HDC hDC; TheSprite->GetDC(&hDC); hDCImage = CreateCompatibleDC(hDC); SelectObject(hDCImage, bitmap); BitBlt( hDC, 0, 0, width, height, hDCImage, 0, 0, SRCCOPY ); TheSprite->ReleaseDC(hDC); DeleteDC( hDCImage ); DeleteObject(bitmap); now, all you have to do in the game loop, is to BackBuffer->BltFast(x,y,TheSprite,&rect,DDBLTFAST_NOCOLORKEY);

and it should appear.
i hope it helped,
Gil

Micro\$oft beta testing:
"Does the splash screen works? SHIP IT!!!"

Edited by - gilzu on July 30, 2001 6:23:22 PM