Thread: Loading BMP to a DirectDrawSurface

  1. #1
    Registered User
    Join Date
    May 2002

    Loading BMP to a DirectDrawSurface

    Does this code do it right???
    Im getting the surface but theres some wierd stuff in it, definitley no bitmap of mine.
    This isnt all my code so i dont quite understand parts of it, for example, the GetObject, well anyway...
    ddMain is IDirectDraw7*.

    bool CreateSurfaceFromBMP( IDirectDrawSurface7** ppSurface,
                               TCHAR* strBMP,                                            
                               DWORD dwDesiredWidth, 
                               DWORD dwDesiredHeight )
        HBITMAP        hBMP = NULL;
        BITMAP         bmp;
        DDSURFACEDESC2 ddsd;
        *ppSurface = NULL;
    	hBMP = (HBITMAP) LoadImage( NULL, strBMP, 
                                    IMAGE_BITMAP, dwDesiredWidth, dwDesiredHeight, 
                                    LR_LOADFROMFILE | LR_CREATEDIBSECTION );
        // Get size of the bitmap
        GetObject( hBMP, sizeof(bmp), &bmp );
        // Create a DirectDrawSurface for this bitmap
        ZeroMemory( &ddsd, sizeof(ddsd) );
        ddsd.dwSize         = sizeof(ddsd);
        ddsd.dwFlags        = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
        ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
        ddsd.dwWidth        = bmp.bmWidth;
        ddsd.dwHeight       = bmp.bmHeight;
        // Draw the bitmap on this surface
    	HDC hdcSprite = CreateCompatibleDC( NULL );
    	//Now that the BMP is in a DC, get the DC for the surface
    	//and just blit it using Windows GDI
    	HDC hdcSurface;
        DeleteObject( hBMP );
        return true;

  2. #2
    Registered User
    Join Date
    Apr 2002
    It looks ok to me. There isn't much error checking though! Start using some HRESULT's and you will perhaps find your error. Also this is wrong

    Look at the 4th and 5th parameters. You pass in the width twice. Hope this helps, if not start checking all the return values!! Even if it doesn't help start checking the values, save you time in the long run.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BMP Loading Structs
    By IdioticCreation in forum C++ Programming
    Replies: 4
    Last Post: 07-05-2007, 12:42 PM
  2. how come... (bmp loading)
    By Homunculus in forum Windows Programming
    Replies: 4
    Last Post: 03-21-2006, 09:00 PM
  3. OpenGL, loading BMP Textures?
    By Zeusbwr in forum Game Programming
    Replies: 12
    Last Post: 12-09-2004, 05:16 PM
  4. Loading a should work.
    By VirtualAce in forum Game Programming
    Replies: 12
    Last Post: 08-14-2004, 08:08 AM
  5. Loading BMP without WM_PAINT?
    By SyntaxBubble in forum Windows Programming
    Replies: 3
    Last Post: 01-10-2002, 10:59 PM