Jump to content
  • Advertisement


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


Loading Bitmaps into DirectDraw surfaces

This topic is 6798 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''m trying to load an 8-bit bitmap into a surface (from a resource) with the following routine, but it''s not working out very well. For some reason, Windows seems to be mapping the image to the current palette, even though I specify LR_CREATEDIBSECTION in the call to LoadImage. I know this because the image uses a custom palette, and looks just fine right after I load it (even though I haven''t touched the current palette). If I then change the current palette to the palette used by the image, everything gets all messed up. Any ideas as to why this is happening? Thanks for your time and help. Hookflash LPDIRECTDRAWSURFACE4 Graphics::CreateSurface(char *bmp_res, int cl, int ch, int mf) { // Load bitmap as a resource HBITMAP hbmp = (HBITMAP)LoadImage(hInstance, bmp_res, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION); if (hbmp == NULL) return NULL; // Get bitmap info (in this case, we want the width and height) BITMAP bmp; GetObject(hbmp, sizeof(bmp), &bmp); // Create a surface to copy the bitmap to // This is an overloaded version of CreateSurface that takes the // width and height of the surface to create and returns a ptr LPDIRECTDRAWSURFACE4 lpdds = CreateSurface(bmp.bmWidth, bmp.bmHeight, cl, ch, mf); if (lpdds == NULL) return NULL; // Create DCs to use for copying the bitmap HDC hdcsrc, hdcdest; hdcsrc = CreateCompatibleDC(NULL); if (hdcsrc == NULL) return NULL; if (FAILED(lpdds->GetDC(&hdcdest))) return NULL; // Select the bitmap into src DC and copy it to dest DC HBITMAP hbmold = (HBITMAP)SelectObject(hdcsrc, hbmp); BitBlt(hdcdest, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcsrc, 0, 0, SRCCOPY); // Cleanup SelectObject(hdcsrc, hbmold); DeleteDC(hdcsrc); lpdds->ReleaseDC(hdcdest); DeleteObject(hbmp); return lpdds;

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!