Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 6 123 ... LastLast
Results 1 to 10 of 55

Thread: Fontmaps

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    23

    Fontmaps

    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

    Screenshot

    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
    Posts
    797
    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
    Posts
    23
    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
    Location
    USA
    Posts
    411
    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
    Posts
    23
    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 Guru
    Join Date
    May 2009
    Posts
    4,948
    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.

  7. #7
    Member Regular Contributor
    Join Date
    Dec 2007
    Posts
    253
    I don't know too much about font stuff. But the default font in visual studio 2010 is so blurry, it's enough to give you eye cancer.

  8. #8
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    23
    Quote Originally Posted by Alfonse Reinheart View Post
    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.
    I agree, I came to much the same conclusion. But I was concerned about the performance, since I will have to - as you said - generate the quads. Anyway, I will try that and get back to you on this.

  9. #9
    Member Regular Contributor
    Join Date
    Jan 2005
    Location
    USA
    Posts
    411
    I am pretty sure GDI+ is deprecated too. It's a mess of an API.

    I would like to know myself how this is commonly done. I am thinking when it comes to the rendering you would want to be writing the quads to a dynamic vertex buffer, but I am not sure. Honestly I am surprised if there is not a (commonly used) higher level way to do truetype Unicode with OpenGL.
    God have mercy on the soul that wanted hard decimal points and pure ctor conversion in GLSL.

  10. #10
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    Honestly I am surprised if there is not a (commonly used) higher level way to do truetype Unicode with OpenGL.
    Why would you be surprised by that? Do you know how hard full-fledged Unicode text layout is? I know of exactly two open-source libraries that can do Unicode text layout: ICU and Pango. Both of these libraries are designed to care as little as possible about how you actually render the glyphs.

    Drawing some glyphs with OpenGL is easy. Drawing the right glyphs in the right place with any graphics API is the tricky part.

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
  •