bitmap fonts flickering

Started by manji, July 25, 2009, 17:42:03

Previous topic - Next topic

manji

I am trying to display some fonts on my 3d game. I am using Nehe's lesson 13 (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=13) and when applying it to my game, I see this kind of fonts:
http://img34.imageshack.us/i/flickering.png/
When I try to move the camera, the text flickers.

If it has anything to do with it, from stuff I have read here, the bitsPerPixel of the Display is 24, the problem occurs at both windows and fullscreen mode, vsync doesn't solve anything, as far as I know blending is enabled and gluPerspective parameters are:
GLU.gluPerspective(45.0f,  WINDOW_WIDTH, WINDOW_HEIGHT,  0.1f, 100.0f);


Could someone please give a hint on what to look at?
toyWars game blog: http://toywars.wordpress.com/

Ciardhubh

Quote from: manji on July 25, 2009, 17:42:03
http://img34.imageshack.us/i/flickering.png/
When I try to move the camera, the text flickers.

Maybe it's a polygon stitching issue; two polygons with similar depth values can cause some flickering and interleaved display. Hard to tell from a still shot. If this is the case, polygon offset might help:
http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/polygonoffset.html

Other than that ... could a low quality texture format cause this, i.e. too few bits to display all colours when rendering the text? That's just a random guess, though.

manji

Thank you Ciardhubh. I guess I should look into that... One more hint I can give is that the flickering occurs only I rotate on X or Y axis. If the string is rotating only on Z axis, it is displayed nicely.

I have tried that on Nehes's example as is. I guess that everyone that modifies the code a little, like this for example:
        GL11.glRotatef(cnt2*10, 1.0f, 0.0f, 1.0f); // add rotation
        GL11.glTranslatef(-0.9f + 0.05f * ((float)Math.cos(cnt1)), 0.32f * ((float)Math.sin(cnt2)), -2.0f);                               // Move One Unit Into The Screen

will have the same result.
toyWars game blog: http://toywars.wordpress.com/

bobjob

sounds like it could be a problem with mipmapping.

also make sure the alpha function is set to GL11.glAlphaFunc(GL11.GL_GREATER, 0.1f); // sets aplha function

Ciardhubh

I tried the example myself and I get the same effect:
http://img145.imageshack.us/img145/3096/scrnsht.png

Enabling mipmaps didn't help.

Enabling alpha testing did.
GL11.glEnable(GL11.GL_ALPHA_TEST);
//  GL11.glAlphaFunc(GL11.GL_ALWAYS, 0); // Doesn't work
GL11.glAlphaFunc(GL11.GL_GREATER, .1f); // Works

I don't really understand why, though. Why does discarding fragments with GL_GREATER draw more than GL_ALWAYS? Where are those black fragments coming from?

Disabling depth testing works, too (with and without alpha testing).

manji

Indeed, this solves the problem! I am a noob so I can't say anything more about it, just that I am happy that it works. Furthermore, temporarily enabling alpha testing brings better results than disabling depth testing(in case I wouldn't mind).
Thank you very much both!
toyWars game blog: http://toywars.wordpress.com/