Loading Bitmaps

Started by
3 comments, last by WizHarDx 22 years, 5 months ago
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
who is it that keeps on nicking WizHarD name !! :P
Advertisement
post some code that we can take a look at to find out whats wrong.
Hitalo Soares
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;
}
who is it that keeps on nicking WizHarD name !! :P
Im not sure how its done with DirectDraw but you could try releasing the surface.
surf->Release(); 
G''day!

Are you freeing the other surfaces when you''re done? It looks like this function loads a bitmap into a new surface, so when you load the bitmap for level 2, have you freed the surface for the level 1 bitmap?


Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena

This topic is closed to new replies.

Advertisement