Font flickering with DX9

Started by
3 comments, last by orphankill 16 years, 6 months ago
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)
Advertisement
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...
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?
Yup, that looks correct. Why do you need several sprite Begin() End() pairs per frame?

Sounds like we'll need to see some code.
Because I'm writing text more then once in the frame, and at different times in different functions so I can't contain it in a single Begin() End(). Here's the function I call more than once:

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

This topic is closed to new replies.

Advertisement