Archived

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

Loading Bitmaps

This topic is 5896 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 near the end of making a 2D game. I was testing it & I noticed everytime the a new level was loaded , or someone loaded a game the framerate went down a more & more till eventully (like level 5) it got to 4fps , thats from 30 fps. So the problem has to be with loading the bmp because everytime its a new level || someone loads a game it loads bmp''s to offscreen surface. Is there any way I can stop this , like maybe do I have to clear the memory or something of the surface. please help thanx in advance WizHarD

Share this post


Link to post
Share on other sites
The only problem is the loading of bmp , so here is my bmp function:LPDIRECTDRAWSURFACE7 Graphics::DD_LoadBitmap(char* FileName)
{

HDC hdc;
HBITMAP bitmap;
LPDIRECTDRAWSURFACE7 surf; // off screen surface

// loads image on to bitmap (from file)
bitmap=(HBITMAP)LoadImage(NULL,FileName,IMAGE_BITMAP
,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE);

if(bitmap==NULL) // if fail
{
MessageBox(NULL,FileName,"Error Loading Bitmap",NULL);
return NULL;
}


then you just make an offscreen surface = to it when your on new level || game is loaded

thanx in advance WizHarD
BITMAP BMP;
GetObject(bitmap,sizeof(BITMAP),&BMP);
int surf_height=BMP.bmHeight;
int surf_width=BMP.bmWidth;

HRESULT Result; // check if ddraw function are success
// create offscreen surface
DDSURFACEDESC2 dds; // surface info struct
ZeroMemory(&dds,sizeof(dds));
dds.dwSize=sizeof(DDSURFACEDESC2);
dds.dwFlags=DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT;
dds.ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN;
dds.dwWidth=BMP.bmWidth; //surf_width
dds.dwHeight=BMP.bmHeight; //surf_height

// Create the actual offscreen surface
Result=DD7->CreateSurface(&dds,&surf,NULL);
if(Result!=DD_OK)
{
MessageBox(NULL,"Bitmap Creatin Surface Failed",
"error",NULL);
return NULL;
}
else
{
surf->Restore(); // make sure surfaced is reso

surf->GetDC(&hdc);
HDC bit_dc=CreateCompatibleDC(hdc);
SelectObject(bit_dc,bitmap);
// Blt to offscreen surface
BitBlt(hdc,0,0,surf_width,surf_height,bit_dc,0,0,
SRCCOPY);
surf->ReleaseDC(hdc);
DeleteDC(bit_dc);
}
DeleteObject(bitmap);
return surf;
}

Share this post


Link to post
Share on other sites