CD3DFont affecting the rendering of other pics

Started by
5 comments, last by Metzler 20 years, 5 months ago
Hey, I've got a new problem :

for (int i = 0;i < Num_Messages; i++)
	{
		x2 = Messages.FILE_STRUCT.x;
		y2 = Messages.FILE_STRUCT.y;
		Render.Render(Message.Graphic, x2, y2, &Message.Rect, 0xFFFFFFFF); //bmp render
		x2 = x2 + 2;
		y2 = y2 + 10;
		strncpy(temp_mem, Messages.FILE_STRUCT.message, 4);
		Render.Render(0, x2,y2,0xFF000000, temp_mem); //font render
	}
  </pre>  
All this for iteration does, is rendering a little bmp and displaying a text &#111;n top of it. Now the problem is : It &#111;nly displays the first bitmap and leaves out the remaining bmps… The text is properly displayed for every entry in this list.
Now, when i outcomment the last render-call, every bmp is displayed &#111;n the screen… (but without text, of course)?
If i do the following :
<pre>
for (int i = 0;i < Num_Messages; i++)
	{
		x2 = Messages.FILE_STRUCT.x;
		y2 = Messages.FILE_STRUCT.y;
		Render.Render(Message.Graphic, x2, y2, &Message.Rect, 0xFFFFFFFF); //bmp render
		x2 = x2 + 2;
		y2 = y2 + 10;
	}
	for (int i = 0;i < Num_Messages; i++)
	{
		x2 = Messages.FILE_STRUCT.x;
		y2 = Messages.FILE_STRUCT.y;
		x2 = x2 + 2;
		y2 = y2 + 10;
		strncpy(temp_mem, Messages.FILE_STRUCT.message, 4);
		Render.Render(0, x2,y2,0xFF000000, temp_mem);
	}
  </pre>  
everything works fine. However i need the first case (because of some overdrawing and clipping stuff).
The First Render-method is a call to LPD3DXSPRITE->Draw, the second Render-Call makes displays a font via CD3DFont->DrawText.
Can anybody help me ??

THX in advance.
   </i> 

Edit : Every Render-Call succeeds, at least it (SUCCEEDED(… doesnt fail…

<SPAN CLASS=editedby>[edited by - Metzler &#111;n November 26, 2003 6:54:14 PM]</SPAN>   
Advertisement
I would guess that in your text render call you''re setting some device state that stops your text from rendering.

I don''t know what version of the SDK you''re using and I certainly don''t know what you''re doing inside your custom Render class so it''s hard to pin it down more.

Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena
Sorry, i forgot.
DirectX 9 SDK

And the code for my Font-Render method looks like the following :
bool CWRAP_DG9::Render(int Num_of_Font, float x, float y, D3DCOLOR Font_Color, TCHAR *Text){	if ((Num_of_Font < 0) || (Num_of_Font >= NUM_OF_FONTS)) Num_of_Font = 0;	if (Fonts[Num_of_Font] != NULL)	{		if (!SUCCEEDED(Fonts[Num_of_Font]->DrawText(x,y,Font_Color, Text)))		{			return false;		}		return true;	}	return false;}  

Nothing extraordinary, i assume

For completeness the render-call for the .bmp render :
bool CWRAP_DG9::Render(LPDIRECT3DTEXTURE9 &graphic, float x, float y, RECT *rect, D3DCOLOR color){	if (!SUCCEEDED(lpSprite->Draw(graphic,rect, NULL, NULL, 0.0f,&D3DXVECTOR2(x, y),color))) 	{		return false;	}	return true;} 


[edited by - Metzler on November 26, 2003 7:18:10 PM]
Do you call the begin and end methods for d3dxsprite at any time?

Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena
bool CWRAP_DG9::Begin_Render(){	if (!SUCCEEDED(lpDevice->BeginScene())) return false;	lpDevice->Clear(0, NULL, D3DCLEAR_TARGET, 0xFF000000, 1.0f, 0);	if (!SUCCEEDED(lpSprite->Begin())) return false;	return true;	}bool CWRAP_DG9::End_Render(){	if (!SUCCEEDED(lpSprite->End())) return false;	if (!SUCCEEDED(lpDevice->EndScene())) return false;	HRESULT temp = lpDevice->Present(NULL, NULL, NULL, NULL);	if (temp == D3DERR_INVALIDCALL) 	{		return false;	}	else if (temp == D3DERR_DEVICELOST) 	{		if (!Reset_Mode()) return false;	}	return true;} 


I call the Begin_Render Method at the beginning of the rendering and End_Render at the end, so yes, i call those two functions...
That''s your problem. sprite->Begin sets up all the states that the sprite needs, then D3DFont stomps all over them. Begin isn''t meant to be called once at the beginning of the frame, usually you call it once, then render as much text as you need to, then call end, with no other device changed in between.

If you need to interleave your render calls like that, then just get rid of Begin() and End(). It will call them internally when you draw the sprite, but they get called each time so it''s not the most efficient. If you aren''t drawing many sprites it won''t be too bad.


Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena
Thank you very much ! That did it !

This topic is closed to new replies.

Advertisement