Original Post
Hi
I have a question regarding my backsurface, when I use it there is always information left on the surface from past games. Is it supposed to be like this, should I flush the memory with this code or is something wrong.
And I need some comments about this code I use to draw surfaces on lpDDSBack. Can I do it better, optimise it. I did test it and I did 100000 blt in some 9974 ms.
And I have one more function I need comment on.
//This function prints text, or bitmaps, part of a big surface containing all letters. abc[224] is a RECT array that tells me from where in the bigsurface the letter is.
[edited by - leadorn on February 19, 2003 1:53:41 PM]
[edited by - leadorn on February 19, 2003 1:54:40 PM]
[edited by - leadorn on February 19, 2003 5:47:20 PM]
HRESULT ddrval;
DDPIXELFORMAT ddpf;
ddpf.dwSize = sizeof(ddpf);
if (lpDDSPrimary->GetPixelFormat(&ddpf)==DD_OK)
{
DDBLTFX ddbltfx;
ddbltfx.dwSize = sizeof(ddbltfx);
ddbltfx.dwFillColor = 0;
ddrval = lpDDSBack->Blt(
0, // Destination is entire surface
0, // No source surface
0, // No source rectangle
DDBLT_COLORFILL, &ddbltfx);
}
//TileMap contains a RECT structure that tells me where to copy from in the big tilemaptexturesurface.
bool cGraphic::DrawTexture(unsigned int uix,unsigned int uiy,LPDIRECTDRAWSURFACE Texture,sTilemap *TileMap,unsigned int uiScale)
{
if(lpDD ==0) return false;
if(lpDDSPrimary == 0) return false;
if(TileMap == 0) return false;
if(Texture ==0) return false;
RECT tmp;
tmp.top = uiy;
tmp.left = uix;
tmp.bottom = uiy;
tmp.right = uix;
tmp.bottom += ((TileMap->rect.bottom-TileMap->rect.top)-uiScale);
tmp.right += ((TileMap->rect.right-TileMap->rect.left)-uiScale);
return lpDDSBack->Blt(&tmp,Texture,&TileMap->rect,DDBLT_WAIT|DDBLT_KEYSRC,0) == DD_OK;
}
FontEngine->Print(0,0,"abc123 mysql dvd %d",tax);
bool cFont::Print(int x,int y,char *szText,...)
{
if(Surface == 0) return false;
if(szText == 0) return false;
if(FontTexture == 0) return false;
char szbuffer[1024];
register int iBufferSize = 0;
RECT tmp;
va_list pArgList;
va_start(pArgList,szText);
_vsnprintf(szbuffer,sizeof(szbuffer),szText,pArgList);
iBufferSize = strlen(szbuffer);
tmp.top = y;
tmp.left = x;
tmp.right = x;
tmp.bottom = ((abc[1]->bottom-abc[1]->top)+y);
for(register int i= 0;i < iBufferSize; i++)
{
register unsigned char ucChar = szbuffer[i]-32;
if(((unsigned char)szbuffer[i] < 32) || ((unsigned char)szbuffer[i] > 255)) return false;
int inc = (abc[ucChar]->right-abc[ucChar]->left);
tmp.right +=inc;
if(Surface->Blt(&tmp,FontTexture,abc[ucChar],DDBLT_WAIT|DDBLT_KEYSRC,0) != DD_OK) return false;
tmp.left+=inc;
}
return true;
}