• 12
• 11
• 9
• 10
• 13

# Font flickering with DX9

This topic is 3814 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I've been experiencing a problem with text since I started the development of game. Most of the time (but not always, say 3/4 times) I start my game, the text on the screen will flicker. Disappear and then come back less then a second later, and repeat this forever. The text flickers in the order that it's displayed. For instance, the game title flickers, then immediately afterwards the menu flickers, then the fps display, and then version number. I'm using ID3DXFONT and passing a sprite that I created, but it was still flickering before I started passing my own sprite. It flickers VERY badly if I open the game settings menu and switch resolutions. In fact, if I do that it will disappear for almost an entire seconds before quickly coming and leaving again. Has anyone else experienced this and fixed it? Or have a better way to display text? (and no, it's not because I'm making a random device->Clear() call somewhere in my code, which is what I first suspected)

##### Share on other sites
Aere you using a Z buffer and not clearing it? Or are you only rendering the text every other frame or something? Text normally works fine...

##### Share on other sites
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

That's my clear call, it's right isn't it?. All text is rendered once. I am making several sprite->begin/end calls every frame with the same sprite. Would that effect anything?

##### Share on other sites
Yup, that looks correct. Why do you need several sprite Begin() End() pairs per frame?

Sounds like we'll need to see some code.

	void RenderText(LPSTR text_to_write, RECT *location = NULL, LPD3DXFONT myfont = NULL, DWORD alignment = DT_CENTER | DT_VCENTER, DWORD color = D3DCOLOR_RGBA(255, 255, 255, 255))	{		if (!location)		{			RECT temp = { 300, 300, 800, 600 };			location = &temp;		}				BeginSprite();		if (!myfont)			font->DrawTextA(d3dspr, text_to_write, -1, location, alignment | DT_NOCLIP, color);		else			myfont->DrawTextA(d3dspr, text_to_write, -1, location, alignment | DT_NOCLIP, color);		EndSprite();		location = NULL;	}