Archived

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

CD3DFont affecting the rendering of other pics

This topic is 5136 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

Hey, I've got a new problem :
for (int i = 0;i < Num_Messages; i++)
	{
		x2 = Messages.FILE_STRUCT.x;
		y2 = Messages.FILE_STRUCT[i].y;
		Render.Render(Message.Graphic, x2, y2, &Message.Rect, 0xFFFFFFFF); //bmp render
		x2 = x2 + 2;
		y2 = y2 + 10;
		strncpy(temp_mem, Messages.FILE_STRUCT[i].message, 4);
		Render.Render(0, x2,y2,0xFF000000, temp_mem); //font render
	}
  
All this for iteration does, is rendering a little bmp and displaying a text on top of it. Now the problem is : It only 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 on the screen... (but without text, of course)? If i do the following :
for (int i = 0;i < Num_Messages; i++)
	{
		x2 = Messages.FILE_STRUCT[i].x;
		y2 = Messages.FILE_STRUCT[i].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[i].x;
		y2 = Messages.FILE_STRUCT[i].y;
		x2 = x2 + 2;
		y2 = y2 + 10;
		strncpy(temp_mem, Messages.FILE_STRUCT[i].message, 4);
		Render.Render(0, x2,y2,0xFF000000, temp_mem);
	}
  
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.
Edit : Every Render-Call succeeds, at least it (SUCCEEDED(... doesnt fail... [edited by - Metzler on November 26, 2003 6:54:14 PM]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites