View Full Version : Antialiasing fonts...

11-04-2005, 06:08 PM
Hi all,
i have a bit of a silly question..
I want to use window fonts in my opengl app, but not when it looks all pixelated, is there a way to Antialias the fonts?


11-04-2005, 06:55 PM
can't you just use trilinear filtering to blur the outline a bit up?

11-04-2005, 08:28 PM
Im not sure if i can, as far as i know you use the trilinear filter on a texture, but the fonts are generated from a windows font file.

fontIndex := glGenLists(96);

Font := CreateFont(18, 0, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET,
SelectObject(hDC, Font);
wglUseFontBitmaps(hDC, 0, 256, fontIndex);

I dont know if there is any way to gain access to the bitmaps/data, or what i can do, i looked at an antialiasing extension, but neither of my computers support it :s

if using trilinear on a font is possible, how do i go about doing it?

11-04-2005, 09:51 PM
Personally I wouldn't use wglUseFontBitmaps() if you want any sort of decent quality out of the fonts.

I use AngelCode's Bitmap Font Generator ( http://www.angelcode.com/products/bmfont/ ) and then have some code that takes that texture and draws the text string on screen for me. You then get results like this (an unfinished Dogfight comp entry :) )

11-04-2005, 10:11 PM
Thanx Sly,

I already i have wrote my own font generator and renderer, but i cant see any point of creating several fonts for this if i can use the systems fonts, my application will have support for themes and will have text based applications (eg notepad, etc) and with these i would like to support custom fonts (eg Arial narrow for one, and times new roman for another) and i dont really want to generate 100's if not 1,000's of fonts for this and then have to ship them with every theme if i dont have to.

(been drinking so i hope this makes some sense :roll:)..

If its not possible then i will probably do a hybrid (a bit of both)

11-04-2005, 10:14 PM
Use the best of both. Generate the font texture at the time it is needed. You have the code for the texture generator, and you want to use the fonts available on their system. At runtime, when a font is required, generate the font bitmap using your code to a temporary texture, then load that texture and use it in your font rendering code.

11-04-2005, 10:36 PM
Thats an idea, i will try that soon.. thanx..

On another point, im am using GL_POINT_SMOOTH to smoothen my terrain and i will be using to smoothen my worlds but i have an issue im concerned about.

When i use it it blends with the background, which at first i decided to render the terrain a second time one at: 0, -0.5, 0 and the second at 0, 0, 0, this works ok and does smoothen most of it but of course this doubles the amount vertices to be rendered and when i finished this i will end up having cities (like what you see in GTA 3 and 4) and this wont be a very good approach unless every one has a top range gfx card.. is there a better way around this?

heres some shots to see what i mean:
Without rendering the terrain twice:

With rendering the terrain twice:


11-04-2005, 10:49 PM
I'm not sure I understand what your question or problem is. Yes, rendering the entire terrain twice is not a good thing for any application.

11-04-2005, 11:00 PM
lol sorry,

Basiclly i am using an OpenGL routine that smoothens all lines, points and polygons that are rendered and it does this by antialiasing the edges, how ever it does this for every triangle that is drawn in the terrain, this is shown in my first image, but i have solved this problem by rendering the terrain twice once with out the smooth attribute and the second with it (shown in the second image), but this of course will become a bigger problem when i come to rendering the whole city instead of just the terrain, and i am just woundering if there is a better way of doing this without using a shader or new extensions?

the gl functions im using are:



The Line and Polygon ones arent a problem at the moment because the line one only effects it when i use glPolygonMode(GL_FRONT_AND_BACK, GL_LINE), and i dont really use the polygon one for the terrain..

11-04-2005, 11:06 PM
I do not know much about smoothing in OpenGL. I've got as far as drawing a few triangles and a font. Ok, maybe a bit more than that, but not much. :)

11-04-2005, 11:26 PM
lol no problem, i was reading the OpenGL Red book for anything about antialiasing and found these, it doesnt really go in to that much depth about using all of them :?
Thanx any ways, i am working on your font idea, and if all goes well i will post it and source here...

12-04-2005, 02:28 PM
Ok i have written the new font generator, at the moment it hasnt been incorporated in to my engine and it takes about a minute or 2 to calculate the font at the moment, im going to see if i can speed it up as much as possible otherwise i will just have to save all the font data..

When the font is generated in to a texture it renders 4 font styles: Normal, Bold, Italic, Bold and Italic into the same texture.

When you call textout you can place format strings in to the text these
are: (ignour the underscore!!)
<_b>text<_/b> for Bold text
<_i>text<_/i> for Italic text
<s>text</s> for Bold and Italic text
<c n,n,n>text</c> to colour the text

The example in the screenshot is:
<_b>Bio<_/b>-<_i>Sphere<_/i> - <s><c 1,0.5,0.5>XShell</c></s> [Font <c 0.5,0.5,1>viewer</c>]

Bio-Sphere - XShell [Font viewer]

http://freepgs.com/m109uk/bsFontGen_text.jpg (http://freepgs.com/m109uk/bsFontGen_text.jpg)

http://freepgs.com/m109uk/bsFontGen_font.jpg (http://freepgs.com/m109uk/bsFontGen_font.jpg)

13-04-2005, 12:09 AM

I'v cleaned up some of my code, but i couldnt find any way of speeding up the font generation, most of the time is spent smoothing it and drawing a shadow, so i have added an option to disable this effect.

The original code for the font generation was from Nitrogens font studio 2, with a few modifications...

Heres a new screenshot:
http://freepgs.com/m109uk/bsFontGen_text2.jpg (http://freepgs.com/m109uk/bsFontGen_text2.jpg)

and for the downloads: