Jump to content
  • Advertisement
Sign in to follow this  
orphankill

D3DXFONT Flicker, extremely annoying...

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

Hi, I made a very similar post some time ago but got no response and am hoping this one will work out better. In short: My fonts flicker. Every font on the screen flickers at the same rate. It happens at a 50% ratio. Another words, half the time when I start my game it works fine, the other half not so good. The font flickers 2-3 times per second, and will always start flickering (even if it wasn't before) if I switch resolutions. I'm losing my mind cause I just can't solve this. The function is posted below, it's short, and the Begin/EndSprite functions do just what they say (sprite->Begin...). What could cause this?
	void RenderText(LPSTR mytext_to_write, RECT *mylocation = NULL, LPD3DXFONT myfont = NULL, DWORD myalignment = DT_CENTER | DT_VCENTER | DT_NOCLIP, DWORD mycolor = D3DCOLOR_RGBA(255, 255, 255, 255))
	{
		if (!mytext_to_write)
			return;

		d3ddev->SetRenderState(D3DRS_ZENABLE, FALSE);
		BeginSprite();

		if (!mylocation)
		{
			RECT temp = { 300, 300, 800, 600 };
			mylocation = &temp;
		}

		if (!myfont)
		{
			font->DrawTextA(d3dspr, mytext_to_write, -1, mylocation, myalignment, mycolor);
		}
		else
		{
			myfont->DrawTextA(d3dspr, mytext_to_write, -1, mylocation, myalignment, mycolor);
		}

		EndSprite();
		d3ddev->SetRenderState(D3DRS_ZENABLE, TRUE);
	}

Share this post


Link to post
Share on other sites
Advertisement
The only time I had a problem with flickering fonts is when they were scrolling across the screen more than 1 pixel at a time, and ClearType was on in Windows. I fixed that one by setting move distance to 1 pixel and increasing move speed.

I also had a problem with jagged fonts and that happened because you cannot set blend color to a dark color, since the font glyphs created by D3DXFont are actually white.

I never attempted to use DT_VCENTER or DT_CENTER, so perhaps D3DXFont class cannot handle those properly and causes flicker.

I also did not set any render states manually, I let D3DXSprite handle this.

The last thing I can think of is using Pix. You say your font flickers; so run Pix and get a pix dump of every frame of your program over the period of several seconds. If one frame has text drawn and another one does not, the flicker may be due to some kind of incorrect usage of sprite batching. If all frames have text drawn exactly the same, then the flicker only occurs when you view those frames in real time. In that case, I don't know what the problem could be, but at least you will know more about what is happening.

Share this post


Link to post
Share on other sites
Well it's not the alignment. It also flickers on other computers, so it's not background software. What is "Pix"? I couldn't find it on google (other then a lame shareware image viewer for jpgs). The only reason I set the render state was because I thought the flickering might be cause by a Z-buffer conflict, so I disabled the Z-buffer and then re-enabled it afterwards. That's not it either.

Share this post


Link to post
Share on other sites
Quote:
Original post by orphankill
Well it's not the alignment. It also flickers on other computers, so it's not background software. What is "Pix"? I couldn't find it on google (other then a lame shareware image viewer for jpgs). The only reason I set the render state was because I thought the flickering might be cause by a Z-buffer conflict, so I disabled the Z-buffer and then re-enabled it afterwards. That's not it either.


PIX is a program used for debugging your D3D apps. It comes with the DX SDK, and should be in the DirectX SDK programs group. It's extremely useful, and you should get intimately familiar with it.

Share this post


Link to post
Share on other sites
I wish I had known about PIX sooner. Although it hasn't helped me solve this problem, it will clearly come in handy. Anyway, what it revealed was some frames with no text, others with. I've managed to narrow the problem down as well. My text doesn't flicker unless I switch resolutions (in game) when starting the game windowed. It will also flicker when starting fullscreen AFTER starting windowed and switching resolutions. When I do, it starts flickering in no discernible pattern, but generally 2-3 times a second. Is calling Begin/EndSprite several times a frame a bad thing? It doesn't say so in the SDK. This is driving me insane!

Share this post


Link to post
Share on other sites
So basically, you narrowed this down to a problem with your resolution-changing code. Which wouldn't be surprising, because even recovering from Alt-Tab could be difficult to get to work, and resolution changing is even more advanced.

I guess you will have to examine your resolution changing more closely. You must be forgetting to clean something up when device gets reset for a resolution change. Or to re-initialize something. I never attempted resolution changes, so I can't be more specific.

You may want to look in DXUT (also included with your DirectX SDK) code, and modify it to draw some text. DXUT also supports resolution changes, so change resolution in DXUT and see if text flickers. Which I am willing to bet it will not. Then you will have to set a breakpoint in DXUT's resolution changing code, step through statements, and try to figure out what they do differently.

Share this post


Link to post
Share on other sites
Doh! Apparently calling Release() and Create() on a font is NOT the same thing as calling font->OnLostDevice(), resetting the device, then font->OnResetDevice().
Who knew?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!