Jump to content
  • Advertisement

Archived

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

omegasyphon

bitmap loading function

This topic is 6396 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i was reading the game programming genesis article and he says you could convert the following bitmap loading function to use external files so does anyone know how to make the function load external files?
  
int LoadBitmapResource(LPDIRECTDRAWSURFACE7 lpdds, int xDest, int yDest, int nResID)
{
  HDC hSrcDC;           // source DC - memory device context

  HDC hDestDC;          // destination DC - surface device context

  HBITMAP hbitmap;      // handle to the bitmap resource

  BITMAP bmp;           // structure for bitmap info

  int nHeight, nWidth;  // bitmap dimensions


  // first load the bitmap resource

  if ((hbitmap = (HBITMAP)LoadImage(hinstance, MAKEINTRESOURCE(nResID),
                                    IMAGE_BITMAP, 0, 0,
                                    LR_CREATEDIBSECTION)) == NULL)
    return(FALSE);

  // create a DC for the bitmap to use

  if ((hSrcDC = CreateCompatibleDC(NULL)) == NULL)
    return(FALSE);

  // select the bitmap into the DC

  if (SelectObject(hSrcDC, hbitmap) == NULL)
  {
    DeleteDC(hSrcDC);
    return(FALSE);
  }

  // get image dimensions

  if (GetObject(hbitmap, sizeof(BITMAP), &bmp) == 0)
  {
    DeleteDC(hSrcDC);
    return(FALSE);
  }

  nWidth = bmp.bmWidth;
  nHeight = bmp.bmHeight;

  // retrieve surface DC

  if (FAILED(lpdds->GetDC(&hDestDC)))
  {
    DeleteDC(hSrcDC);
    return(FALSE);
  }

  // copy image from one DC to the other

  if (BitBlt(hDestDC, xDest, yDest, nWidth, nHeight, hSrcDC, 0, 0,
             SRCCOPY) == NULL)
  {
    lpdds->ReleaseDC(hDestDC);
    DeleteDC(hSrcDC);
    return(FALSE);
  }

  // kill the device contexts

  lpdds->ReleaseDC(hDestDC);
  DeleteDC(hSrcDC);

  // return success

  return(TRUE);
}

  

Share this post


Link to post
Share on other sites
Advertisement
Pass a string rather than a resource ID (you can use an optional extra parameter), and use this in LoadImage, and have the LR_LOADFROMFILE (If I remember correctly) flag along with LR_CREATEDIBSECTION, and I think hInstance can be null.

Look up the LoadImage function because that''s the one that does the loading.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
so is this correct:

change
  
int LoadBitmapResource(LPDIRECTDRAWSURFACE7 lpdds, int xDest, int yDest, int nResID)
to
int LoadBitmapResource(LPDIRECTDRAWSURFACE7 lpdds, int xDest, int yDest,char *bitmap)

and

if ((hbitmap = (HBITMAP)LoadImage(hinstance, MAKEINTRESOURCE(nResID), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION)) == NULL)

to

if ((hbitmap = (HBITMAP)LoadImage(hinstance,bitmap, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION)) == NULL)



Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!