If anybody out their has some working source code of a program that blits a bitmap on the screen from a backbuffer and uses LoadImage(), Please send it to me. If you look at my post: ERROR REFIID, you''ll see that I have been trying to do this but to no avail. Please help me out if you can. I would really appreciate it. Thanks!
Check the tutorials on the MXF Entertainment page.
- mallen22@concentric.net
- http://www.cfxweb.net/mxf/
- mallen22@concentric.net
- http://www.cfxweb.net/mxf/
I did, didn't help much. I'm looking to use LoadImage().
Edited by - psychoprog on 2/28/00 2:38:52 PM
Edited by - psychoprog on 2/28/00 2:38:52 PM
I tried going there agin to see I had missed something and to see if a new tutorial had been added since the last time I had been there, but the site wouldn''t come up. Click here and if you can''t get through to the site, please post it up. Is the site down? What''s wrong?
I can''t get to that site either.
One person said that the games industry is "a transfer of funds from the rich to the lucky"
One person said that the games industry is "a transfer of funds from the rich to the lucky"
Maybe so, but I was just at the site yesterday. That''s where I was looking for tutorials on bitmaps. I''m sure that the problem is just temporary.
Getting back to the topic, If anyone has any source code for anything that displays a bitmap on screen using LoadBitmap() I''d appreciate it. I am also interested in game source code.
Getting back to the topic, If anyone has any source code for anything that displays a bitmap on screen using LoadBitmap() I''d appreciate it. I am also interested in game source code.
It''s a bloody shame the site didn''t work... This code is from the Tetris clone on that "not working" site.
//--------------------------------------------------------------------------------------------
// Bitmap_Load()
// Load a bitmap into video memory. This function creates a surface for the bitmap, too.
//--------------------------------------------------------------------------------------------
LPDIRECTDRAWSURFACE7 Bitmap_Load( LPDIRECTDRAW7 lpDDTemp, LPCSTR szBitmap )
{
HBITMAP hbm; // A handle to the bitmap in memory.
BITMAP bm; // Used to get information about the bitmap.
DDSURFACEDESC2 ddsd; // A description of a DD surface, used to create it.
LPDIRECTDRAWSURFACE7 lpDDSTemp; // Temporary pointer to the DD surface.
// Try to load the bitmap as a resource, if that fails, try it as a file.
if ( ( hbm = ( HBITMAP ) LoadImage( GetModuleHandle( NULL ), szBitmap, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION ) ) == NULL )
if ( ( hbm = ( HBITMAP ) LoadImage( NULL, szBitmap, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE / LR_CREATEDIBSECTION ) ) == NULL )
return NULL; // Return NULL because it is expecting a surface, and NULL is not going to be a surface. It seems to make more sense than returning FALSE or E_FAIL, but I don''t know...
// Get size of the bitmap.
if ( GetObject( hbm, sizeof( bm ), &bm ) == FALSE )
return NULL;
// Create a DirectDrawSurface for this bitmap.
ZeroMemory( &ddsd, sizeof( ddsd ) );
ddsd.dwSize = sizeof( ddsd );
ddsd.dwFlags = DDSD_CAPS / DDSD_HEIGHT / DDSD_WIDTH; // We want to specify the height and width.
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; // Make the surface in video memory.
ddsd.dwWidth = bm.bmWidth;
ddsd.dwHeight = bm.bmHeight;
// Create the surface for the bitmap.
if ( FAILED( lpDDTemp->CreateSurface( &ddsd, &lpDDSTemp, NULL ) ) )
return NULL;
// Copy the bitmap into the surface.
if ( FAILED( Bitmap_Copy( lpDDSTemp, hbm ) ) )
return NULL;
// Once the bitmap is copied to the surface, we no longer need hbm.
if ( DeleteObject( hbm ) == FALSE )
return NULL;
// Return the surface.
return lpDDSTemp;
}
//--------------------------------------------------------------------------------------------
// Bitmap_ReLoad()
// Reload a bitmap into a surface that already exists.
//--------------------------------------------------------------------------------------------
BOOL Bitmap_ReLoad( LPDIRECTDRAWSURFACE7 lpDDSTemp, LPCSTR szBitmap )
{
HBITMAP hbm;
// Try to load the bitmap as a resource, if that fails, try it as a file.
if ( ( hbm = ( HBITMAP ) LoadImage( GetModuleHandle( NULL ), szBitmap, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION ) ) == NULL )
if ( ( hbm = ( HBITMAP ) LoadImage( NULL, szBitmap, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE / LR_CREATEDIBSECTION ) ) == NULL )
return FALSE; // We don''t want the Error() funcion here, the function that called this will also call that.
// Copy the bitmap to the surface.
if ( Bitmap_Copy( lpDDSTemp, hbm ) == FALSE )
return FALSE;
if ( DeleteObject( hbm ) == FALSE )
return FALSE;
return TRUE;
}
//--------------------------------------------------------------------------------------------
// Bitmap_Copy()
//--------------------------------------------------------------------------------------------
BOOL Bitmap_Copy( LPDIRECTDRAWSURFACE7 lpDDSTemp, HBITMAP hbm )
{
HDC hdcImage; // Device contexts, needed for BitBlt().
HDC hdc;
BITMAP bm; // The bitmap info.
DDSURFACEDESC2 ddsd; // A description of a DD surface.
// If we didn''t get passed usable objects, return an error code.
if ( hbm == NULL // lpDDSTemp == NULL )
return FALSE;
// Make sure this surface is restored.
if ( FAILED( lpDDSTemp->Restore() ) )
return FALSE;
// Select bitmap into a memoryDC so we can use it.
if ( ( hdcImage = CreateCompatibleDC( NULL ) ) == FALSE )
return FALSE;
if ( SelectObject( hdcImage, hbm ) == NULL )
return FALSE;
// Get size of the bitmap.
GetObject( hbm, sizeof( bm ), &bm );
// Get size of surface.
ddsd.dwSize = sizeof( ddsd );
ddsd.dwFlags = DDSD_HEIGHT / DDSD_WIDTH;
// Get the height and width of the surface.
if ( FAILED( lpDDSTemp->GetSurfaceDesc( &ddsd ) ) )
return FALSE;
// Blit the image into the surface. Use a DC because we are using the Win32 API to blit.
if ( FAILED( lpDDSTemp->GetDC( &hdc ) ) )
return FALSE;
else
{
// Blit the bitmap to the DirectDraw surface.
if ( BitBlt( hdc, 0, 0, ddsd.dwWidth, ddsd.dwHeight, hdcImage, 0, 0, SRCCOPY ) == FALSE )
return FALSE;
if ( FAILED( lpDDSTemp->ReleaseDC( hdc ) ) )
return FALSE;
}
if ( DeleteDC( hdcImage ) == FALSE )
return FALSE;
return TRUE;
}
- mallen22@concentric.net
- http://www.cfxweb.net/mxf/
//--------------------------------------------------------------------------------------------
// Bitmap_Load()
// Load a bitmap into video memory. This function creates a surface for the bitmap, too.
//--------------------------------------------------------------------------------------------
LPDIRECTDRAWSURFACE7 Bitmap_Load( LPDIRECTDRAW7 lpDDTemp, LPCSTR szBitmap )
{
HBITMAP hbm; // A handle to the bitmap in memory.
BITMAP bm; // Used to get information about the bitmap.
DDSURFACEDESC2 ddsd; // A description of a DD surface, used to create it.
LPDIRECTDRAWSURFACE7 lpDDSTemp; // Temporary pointer to the DD surface.
// Try to load the bitmap as a resource, if that fails, try it as a file.
if ( ( hbm = ( HBITMAP ) LoadImage( GetModuleHandle( NULL ), szBitmap, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION ) ) == NULL )
if ( ( hbm = ( HBITMAP ) LoadImage( NULL, szBitmap, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE / LR_CREATEDIBSECTION ) ) == NULL )
return NULL; // Return NULL because it is expecting a surface, and NULL is not going to be a surface. It seems to make more sense than returning FALSE or E_FAIL, but I don''t know...
// Get size of the bitmap.
if ( GetObject( hbm, sizeof( bm ), &bm ) == FALSE )
return NULL;
// Create a DirectDrawSurface for this bitmap.
ZeroMemory( &ddsd, sizeof( ddsd ) );
ddsd.dwSize = sizeof( ddsd );
ddsd.dwFlags = DDSD_CAPS / DDSD_HEIGHT / DDSD_WIDTH; // We want to specify the height and width.
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; // Make the surface in video memory.
ddsd.dwWidth = bm.bmWidth;
ddsd.dwHeight = bm.bmHeight;
// Create the surface for the bitmap.
if ( FAILED( lpDDTemp->CreateSurface( &ddsd, &lpDDSTemp, NULL ) ) )
return NULL;
// Copy the bitmap into the surface.
if ( FAILED( Bitmap_Copy( lpDDSTemp, hbm ) ) )
return NULL;
// Once the bitmap is copied to the surface, we no longer need hbm.
if ( DeleteObject( hbm ) == FALSE )
return NULL;
// Return the surface.
return lpDDSTemp;
}
//--------------------------------------------------------------------------------------------
// Bitmap_ReLoad()
// Reload a bitmap into a surface that already exists.
//--------------------------------------------------------------------------------------------
BOOL Bitmap_ReLoad( LPDIRECTDRAWSURFACE7 lpDDSTemp, LPCSTR szBitmap )
{
HBITMAP hbm;
// Try to load the bitmap as a resource, if that fails, try it as a file.
if ( ( hbm = ( HBITMAP ) LoadImage( GetModuleHandle( NULL ), szBitmap, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION ) ) == NULL )
if ( ( hbm = ( HBITMAP ) LoadImage( NULL, szBitmap, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE / LR_CREATEDIBSECTION ) ) == NULL )
return FALSE; // We don''t want the Error() funcion here, the function that called this will also call that.
// Copy the bitmap to the surface.
if ( Bitmap_Copy( lpDDSTemp, hbm ) == FALSE )
return FALSE;
if ( DeleteObject( hbm ) == FALSE )
return FALSE;
return TRUE;
}
//--------------------------------------------------------------------------------------------
// Bitmap_Copy()
//--------------------------------------------------------------------------------------------
BOOL Bitmap_Copy( LPDIRECTDRAWSURFACE7 lpDDSTemp, HBITMAP hbm )
{
HDC hdcImage; // Device contexts, needed for BitBlt().
HDC hdc;
BITMAP bm; // The bitmap info.
DDSURFACEDESC2 ddsd; // A description of a DD surface.
// If we didn''t get passed usable objects, return an error code.
if ( hbm == NULL // lpDDSTemp == NULL )
return FALSE;
// Make sure this surface is restored.
if ( FAILED( lpDDSTemp->Restore() ) )
return FALSE;
// Select bitmap into a memoryDC so we can use it.
if ( ( hdcImage = CreateCompatibleDC( NULL ) ) == FALSE )
return FALSE;
if ( SelectObject( hdcImage, hbm ) == NULL )
return FALSE;
// Get size of the bitmap.
GetObject( hbm, sizeof( bm ), &bm );
// Get size of surface.
ddsd.dwSize = sizeof( ddsd );
ddsd.dwFlags = DDSD_HEIGHT / DDSD_WIDTH;
// Get the height and width of the surface.
if ( FAILED( lpDDSTemp->GetSurfaceDesc( &ddsd ) ) )
return FALSE;
// Blit the image into the surface. Use a DC because we are using the Win32 API to blit.
if ( FAILED( lpDDSTemp->GetDC( &hdc ) ) )
return FALSE;
else
{
// Blit the bitmap to the DirectDraw surface.
if ( BitBlt( hdc, 0, 0, ddsd.dwWidth, ddsd.dwHeight, hdcImage, 0, 0, SRCCOPY ) == FALSE )
return FALSE;
if ( FAILED( lpDDSTemp->ReleaseDC( hdc ) ) )
return FALSE;
}
if ( DeleteDC( hdcImage ) == FALSE )
return FALSE;
return TRUE;
}
- mallen22@concentric.net
- http://www.cfxweb.net/mxf/
Well, donno why the site didn''t work (it does now!) Anyway, if that happens again email me at civax@mail.com
---
Ohad Barzilay, aka Civax / CFXweb, http://cfxweb.planet-d.net
---
Ohad Barzilay, aka Civax / CFXweb, http://cfxweb.planet-d.net
Thanks, I appreciate the help. But I have my own function (it doesn''t work). Could you take a look at it and tell me what''s wrong?:
bool LoadBMP(LPDIRECTDRAWSURFACE4 &surface, LPSTR filename, int bmpwidth, int bmpheight,
int surfacewidth, int surfaceheight)
{
//set the surface capablilities
DDSURFACEDESC2 ddsd2;
ddsd2.dwSize =sizeof(ddsd2);
ddsd2.dwFlags =DDSD_CAPS/DDSD_HEIGHT/DDSD_WIDTH;
ddsd2.dwWidth =640;
ddsd2.dwHeight =480;
ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
//create the surface
if(FAILED(lpdd4->CreateSurface(&ddsd2, &surface, NULL)))
return FALSE;
HBITMAP hbm;
HDC imagedc;
HDC surfacedc;
//load the bitmap into the object
hbm = (HBITMAP)LoadImage(NULL, filename, IMAGE_BITMAP, bmpwidth,
bmpheight, LR_LOADFROMFILE/LR_CREATEDIBSECTION);
//check if the function didn''t work
if(hbm == NULL)
return FALSE;
//select the object
imagedc = CreateCompatibleDC(NULL);
SelectObject(imagedc, hbm);
//lock the surface
if(FAILED(surface->GetDC(&surfacedc)))
return FALSE;
//blit the info to the surface
if(BitBlt(surfacedc, 0, 0, surfacewidth, surfaceheight,
imagedc, 0, 0, SRCCOPY)== FALSE)
return FALSE;
//delete objects
if(surfacedc)
{
surface->ReleaseDC(surfacedc);
}
if(imagedc)
{
DeleteDC(imagedc);
}
if(hbm)
{
DeleteObject(hbm);
}
return TRUE;
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement