Jump to content
  • Advertisement

Archived

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

-Dyger-

loading bitmaps into DDraw surfaces

This topic is 6528 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

Hi, I am using lamothes code, and he has functions that load bitmaps files into bitmap images, but he says u cant blit the bitmal images, so whats the point of that???, dont u have to create an offscreen surface and load the bitmap into to surface so u can blit it???, Ive looked thru his book, and i cant figure out how to do this, could someone please enlighten me on how to load a simple 32*32 16 bit bitmap into an offscreen surface that i made? thanks

Share this post


Link to post
Share on other sites
Advertisement
First of all you load the bitmap - Load_Bitmap("file.bmp",&bitmap16bit);
Then you have to copy the bitmap to the surface.
Lamothe''s Load_Frame_BOB16() copies the bitmap to the surface so have a look at it.



The road to success is always under construction

Share this post


Link to post
Share on other sites
Im not sure but I dont think lamothes code is meant for 16 bit images, just 8 bit. heres the code I use to load a bitmap:

    

HDC hdc;
HBITMAP bit;
LPDIRECTDRAWSURFACE7 surf=NULL;

// load the bitmap

bit=(HBITMAP) LoadImage(NULL,file_name,IMAGE_BITMAP,0,0,
LR_DEFAULTSIZE|LR_LOADFROMFILE);
if (!bit)
// failed to load, return failure to caller
return 0;

// get bitmap dimensions

BITMAP bitmap;
GetObject( bit, sizeof(BITMAP), &bitmap );
int surf_width=bitmap.bmWidth;
int surf_height=bitmap.bmHeight;

// create surface

HRESULT ddrval;
DDSURFACEDESC2 ddsd;
ZeroMemory(&ddsd,sizeof(ddsd));
ddsd.dwSize = sizeof(DDSURFACEDESC2);
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT ;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwWidth = surf_width;
ddsd.dwHeight = surf_height;

// attempt to create surface

ddrval=lpDD->CreateSurface(&ddsd,&surf,NULL);

// created ok?

if (ddrval!=DD_OK)
{
// no, release the bitmap and return failure to caller
DeleteObject(bit);
return 0;
}

else
{
// yes, get a DC for the surface
surf->GetDC(&hdc);

// generate a compatible DC

HDC bit_dc=CreateCompatibleDC(hdc);

// blit the interface to the surface

SelectObject(bit_dc,bit);
BitBlt(hdc,0,0,surf_width,surf_height,bit_dc,0,0,SRCCOPY);

// release the DCs

surf->ReleaseDC(hdc);
DeleteDC(bit_dc);

// save the dimensions if rectangle pointer provided

if (dims)
{
dims->left=0;
dims->top=0;
dims->right=surf_width;
dims->bottom=surf_height;
}
}

// clear bitmap

DeleteObject(bit);


now surf has the bitmap loaded into it and you can blit it

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!