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


DirectDraw 7 Surface + Bitmaps

Recommended Posts

I am new to DirectX programming. I have the DX8 SDK and am using BCB6. I am trying to load a bitmap from a file into a CSurface. When I initialize DirectDraw, I call dispDisplay->CreateSurface(&surfBitmap,256,256); dispDisplay->Blt(100,300,surfBitmap,NULL); surfBitmap->Create(dispDisplay->GetBackBuffer()); and then in my game loop, I call surfBitmap->DrawBitmap(bmp->Handle, 100, 300, 256, 256); where *bmp is a Graphics::TBitmap that is loaded in my form''s constructor. When I run my program, however, I just get garbage where my bitmap is supposed to show up. What should I do (that doesn''t require tons of code) to load a bitmap onto my surface? Note: this method works just fine if I call DrawTextA. langguy

Share this post

Link to post
Share on other sites
Hope it helps,

LPDIRECTDRAWSURFACE7 CreateSurfaceFromFile( LPDIRECTDRAW7 DDraw, char * file,
bool videomemory )
HBITMAP hbmp; // bitmap handle

BITMAP bitmap; // temporary bitmap

HDC hdcImagem; // image handle

HDC hdcSurface; // surface handle

LPDIRECTDRAWSURFACE7 ddsSurface; // superficie pointer


// open bitmap

hbmp = ( HBITMAP ) LoadImage( NULL, file, IMAGE_BITMAP, 0, 0,

if( hbmp == NULL )
return NULL;

// get image width and height (pixels)

GetObject( hbmp, sizeof( BITMAP ), ( void *) &bitmap );

memset( &ddsdAux, 0, sizeof( DDSURFACEDESC2 ) );

// describe surface

ddsdAux.dwSize = sizeof( DDSURFACEDESC2 );
ddsdAux.dwWidth = bitmap.bmWidth;
ddsdAux.dwHeight = bitmap.bmHeight;
ddsdAux.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;

ddsdAux.ddsCaps.dwCaps |= videomemory ? DDSCAPS_VIDEOMEMORY :

// try to create the surface

hr = DDraw->CreateSurface( &ddsdAux, &ddsSurface, NULL );

if( hr != DD_OK )
return NULL;

hdcImagem = CreateCompatibleDC( NULL );
SelectObject( hdcImagem, hbmp );

// get surface DC...

ddsSurface->GetDC( &hdcSurface );

if( hdcSurface == NULL )
return NULL;

// we can blit the image onto it

if( BitBlt( hdcSurface, 0, 0, ddsdAux.dwWidth, ddsdAux.dwHeight, hdcImagem,
0, 0, SRCCOPY ) == false )
ddsSurface->ReleaseDC( hdcSurface );
return NULL;

// release resources

ddsSurface->ReleaseDC( hdcSurface );
DeleteDC( hdcImagem );
DeleteObject( hbmp );

return ddsSurface;

"- To begin with, said the Cat, a dog's not mad. You grant that?
- I suppose so, said Alice.
- Well, then, - the Cat went on - you see, a dog growls when it's angry, and wags its tail when it's pleased. Now I growl when I'm pleased, and wag my tail when I'm angry. Therefore I'm mad."

[edited by - Andre Luiz Silva on January 22, 2003 9:08:21 AM]

Share this post

Link to post
Share on other sites