Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 55

Thread: Fontmaps

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member Newbie
    Join Date
    Aug 2012


    Hi there,

    I wanted to share a (glimpse at a) cool thing that I made and ask how I could improve it. I am really giddy about the fact that it worked out nicely, so excuse the gloating that's inevitably present in the description below

    It's a fontmap generator. It can take any font, either installed or from a custom file and draw a condensed (bin packed) fontmap of symbols in any size and style using GDI+.
    You then request a character and it returns its position, size and the index of the texture it's currently contained in.
    It's also fully dynamic, so if you request a character that hasn't been before generated (and you allow the fontmap to be dynamic), the fontmap will automatically generate the character, add it to the texture and return the symbol.
    The image below took +/- 13 seconds (it's 13000+ symbols in all styles possible and a lot of sizes). It's a 2048x2048


    The text below has been written with the symbols that were dynamically generated, added to the fontmap and then extracted to be applied on quads. I love it.

    But enough with the gloating, I dearly need some advice. Do the fonts look okay when you see them? Could you look at a text like this for a long time? I have been continually staring at these fonts for so long that I honestly can't tell. Sometimes the font looks too blurry (GDI+ is set to AntiAliasGridFit), but japanese and arabic symbols look too pixelated. Using AntiAlias (No grid fit) fixes the second problem, but sometimes augments the blurriness on thin lines, makes them gray instead of black.

    And second, (I know this is an OpenGL forum, but whom better to ask than you people, many of whom attempted the same thing, I'm sure) where could I find any information that could help me with creating my own GUI? Namely textboxes - none of my pitiful attempts at creating a textbox control succeeded. I need some design, structure or anything that would explain how exactly does a textbox (like the one I'm using right now) effectively manage its text.

    Thank you for any help

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    One idea to improve the quality: render a character at a much larger size, calculate a distance map from it, and store that in your fontmap texture, see Alpha Tested Magnification.pdf for details.

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2012
    Thanks for the suggestion, but this seems like more work than it would be worth. At least for now, when it's more important to get a basic UI going.

  4. #4
    Member Regular Contributor
    Join Date
    Jan 2005
    I used to do quad fonts with OpenGL. But I have been basically working with Direct3D (no more than 9) for a long time since, but intend to get back into desktop OpenGL soon because it will be possible to move away from Direct3D (breaking away from legacy inertia) and because Direct3D is a dead end on Windows XP but OpenGL is not.

    If you are using GDI+ then we are talking about Windows. I do not know about post D3D9 but there is D3DXCreateFont which I have tended to favor; especially because I needed to emulate the earlier Win32 Font APIs but in general if Unicode and i18n is a must D3DXCreateFont really does a lot for free. And it seem like it probably works similarly to what you (Inagawa) are doing here. Except obviously it's not OpenGL!

    I don't know how it stacks up against the kind of font rendering we expect in a web browser. But it you need quite large or single pixel fonts it looks good.

    But now what I am wondering is what on earth I will do if I am using OpenGL instead of Direct3D9. I know D3DX has a lot of "OpenGL" mode features. But I am just assuming the two are not compatible due to namesakes if nothing else. I would actually need to be able to emulate the Win32 APIs on Windows at least so this kind of approach will probably be a must.

    Anyway at OP. If nothing else you might consider firing up Direct3D instead of GDI. As GDI is deprecated anyway. And drawing to a device context. And then copying that to OpenGL somehow. The main OpenGL context handle on Windows is a device context, so it would probably be compatible. But it would be nice to break away from micromanaging the placement too. I am wondering if GLUT has a way? I see wglUseFontOutlines.
    Last edited by michagl; 09-23-2012 at 07:32 PM.
    God have mercy on the soul that wanted hard decimal points and pure ctor conversion in GLSL.

  5. #5
    Junior Member Newbie
    Join Date
    Aug 2012
    I am using GDI+, not GDI. And if I'm not mistaken, DirectWrite is the only thing superseding GDI+, no? I may be wrong, though. I really needed some robust way of rendering text as soon as possible so I can finally move on and get to programming the rest of the GUI, so GDI+ seemed like the obvious choice after picking apart the source code of other GUIs.

    So to be honest, at this point I am far more interested in how to program an editable text box. For the life of me I can't figure it out. I don't have the luxury of thinking about the text as a string (and just render the text line by line with GDI+ like others do), but as a collection of quads and that complicates things beyond my capabilities. If anyone could please enlighten me even by a little, I'd be grateful, but as far as the matter with the fontmap goes, I can't change anything now.

    Edit: Where are my manners, thank you for the advice, don't think I don't value it; it's just that by now my priorities are shifted away from the actual fontmap.
    Last edited by Inagawa; 09-24-2012 at 10:19 AM.

  6. #6
    Senior Member OpenGL Lord
    Join Date
    May 2009
    I don't have the luxury of thinking about the text as a string (and just render the text line by line with GDI+ like others do), but as a collection of quads and that complicates things beyond my capabilities.
    That... is why you fail.

    You're trying to think about a text box at the level of quad drawing. That's the wrong way to go; you should be thinking of text boxes at the level of the string, which you then use to generate the list of quads to draw.

    Your edit box has two levels of functionality: modify a string based on user-input, and draw that string. If you try to do both of these at the same time, you won't get anywhere.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts