Skip to main content
gamedev.net
🔒 Locked

DDraw back buffer & code comment

Started by Leadorn 2 replies 250+ views
Original Post
Leadorn
Leadorn
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.
        
	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); 
		  
			
			  
	}
  
  
  
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.
  
      
//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;
}
  
   
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.
  

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;
	
}

        
[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]
Leadorn
Leadorn
Anyone?
directrix
directrix
ok first question, yes the backbuffer is supposed to be like that, and you don''t have to clear it if you don''t need to. If you draw something on top of it you''ll simply overwrite it.

second question, code looks good but BltFast may be faster (not sure).

third, can''t think of how you might speed it up aside from getting rid of the variable argument list, but it might not be worth it. why are you using the register keyword? does it actually give a performance boost?

digital radiation
Leadorn
Leadorn
nope, using register doesn’t make any difference. But I can tell you this, don’t use DDSCAPS_SYSTEMMEMORY in the Createsurface if you can. Hehe... there was a big big big speed diff.

I wrote earlier about blitering 100000 in 9974 ms, yea but now with the video memory like 429 ms.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.