Sign in to follow this  
cozman

OpenGL Bitmap fonts & bitmap font generators (SOLVED)

Recommended Posts

cozman    583
It's come time for me to revamp my font engine in OpenGL for an upcoming project. I am currently using bitmapped fonts but I really hate them. After a good day or so of screwing with FTGL and a few other half-baked libraries I think I've settled on bitmap fonts again unfortunately. (If I'm missing some great new font library someone please clue me in [smile]) Anyway, I realized that since I switched to Linux, one of the things I haven't done is generate a bitmap font. What cross-platform (preferably, but I'll take linux-only) bitmap font generators are there. The only decent one I had is Windows only, and while I could possibly get it running under Cedega, I'd really like to have a native solution. EDIT: I ended up writing my own solution, feel free to check it out. [Edited by - cozman on July 1, 2005 1:37:13 PM]

Share this post


Link to post
Share on other sites
void*    292
take a look at TXF fonts for mip-mapped bitmap texture fonts... the page even includes a utility for converting .bdf fonts to .txf fonts. And, since you're running Linux, you probably already have a lot of .bdf fonts on your system.

The code is all straight C and even makes room for older implementations of OpenGL (it only assumes OpenGL v1.0 but uses texture objects if they're in the library you compile with). The code is really understandable and I found it easy to convert to C++ and my own (extended) file format. TXF is my top suggestion. (Even though I don't think his coloring extensions are really that useful (I removed them in my implementation) -- but they're a good example of how you can extend the font library). Oh, and you could also change the rasterization step so that it doesn't do an availability lookup for each character *every_time* the text is drawn.

There is also SDL_ttf (if you want to distribute .ttf fonts with your game, but then you're limited to using copyright-free fonts) and PLib has its own font rendering (but I think it's based off of TXF, anyway). I agree that bitmap fonts are probably a better solution than rasterized fonts, and almost certainly a better solution than 3D (polygonal) fonts... (depends on what you're using the font for). In the end it might be best to just write your own, tailored to how you will be using it.

HTH

Share this post


Link to post
Share on other sites
strtok    191
I've recently completed porting my utility, glFont (http://students.cs.byu.edu/~bfish/glfont.php), to wxWidgets, and it is now fully cross-platform. I'm actually open sourcing it very soon. If you're interested, however, I can get you an early copy :-). Just drop me a line at brad.fish@gmail.com.

Share this post


Link to post
Share on other sites
_the_phantom_    11250
personally I plan on pulling something together using Freetype 2 (raw, not using a wrappin lib, I did look at some of them but they looked.. insane.. ).

I admit, it took me a couple of days to get things going, but it did give wonderful output (properly positions and kerned text just like Windows makes.. hmmm lovely [wink]), although i need todo some more work on the caching side of things as my solution is a tad.. suboptimial.. to say the least [grin]

Basically, the hardest bit of using FT2 raw is that you have to manage the finer glyth details yourself, however once the stuff is in memory one glsubtex upload later and you have some nice, antialised, fonts.

Example output from my Multi-thread game loop test, and I waffle abit about it in my journal on here.

Share this post


Link to post
Share on other sites
cozman    583
thanks for the great replies guys,

One thing that I want from my font system is for it to be usable by people other than me, so I want the fonts to be relatively easy to create. Truetype fonts are the most common, and the nicest since they can be scaled, etc.

I'd looked into txf earlier and of the three options txf is the most obscure and

glFont looks really good, I stumbled upon it earlier in my searches but like the rest noticed it didn't run under Linux, if this post didn't turn up something similar, I was planning on writing something similar in wxPython. I sent you an email, I'd love to give it a try.

something custom using Freetype 2 was my ideal plan, but for the time being isn't practical since I don't have a ton of time to spend on the font system. (Also, as for the wrapper libs being 'insane' I'd have to agree, I'd like to see/make an effort to design a simpler approach to using TTF fonts in OpenGL)

edit: Just saw your post sergeant_x, and I concur although in the future I'd recommend using the Private Message system to let me know you're a fan (to those not in the know he was referencing my avatar)

Share this post


Link to post
Share on other sites
cozman    583
Thanks for sending that strtok, if I end up going with bitmapped fonts it will almost certainly be due to glfont.

I came upon what seems to be a not-so-insane FreeType wrapper library that for some reason wasn't coming up in my earlier searches. OGLFT seems like it might be worth checking out.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
AngelCode's bitmap generator is an awesome piece of software, if you have not yet seen it. The bitmap fonts generated come with a description file, which when used correctly, allows you to draw characters with varying sizes making it look more natural.

Share this post


Link to post
Share on other sites
cozman    583
I found a guy who wrote his own font generator using FreeType that was extremely simple fonttool. I decided to adapt this to cut out the middle step, which resulted in an extremely simple but somewhat useful class. I've released my work as GLFT_Font.

It's extremely easy to use:

#include "GLFT_Font.h"

...
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
...
Font fnt("somefont.ttf", size);
...
fnt.drawText(x, y, "Hello World");


It's open source and BSD-licensed, any improvements/bug-fixes/suggestions would be greatly appreciated. I think it's about time that there is a simple method for rendering TTF files under OpenGL.

(By the way, it's just as fast at rendering as bitmap fonts. Essentially all this does is generate then load a bitmap font.)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By pseudomarvin
      I assumed that if a shader is computationally expensive then the execution is just slower. But running the following GLSL FS instead just crashes
      void main() { float x = 0; float y = 0; int sum = 0; for (float x = 0; x < 10; x += 0.00005) { for (float y = 0; y < 10; y += 0.00005) { sum++; } } fragColor = vec4(1, 1, 1 , 1.0); } with unhandled exception in nvoglv32.dll. Are there any hard limits on the number of steps/time that a shader can take before it is shut down? I was thinking about implementing some time intensive computation in shaders where it would take on the order of seconds to compute a frame, is that possible? Thanks.
    • By Arulbabu Donbosco
      There are studios selling applications which is just copying any 3Dgraphic content and regenerating into another new window. especially for CAVE Virtual reality experience. so that the user opens REvite or CAD or any other 3D applications and opens a model. then when the user selects the rendered window the VR application copies the 3D model information from the OpenGL window. 
      I got the clue that the VR application replaces the windows opengl32.dll file. how this is possible ... how can we copy the 3d content from the current OpenGL window.
      anyone, please help me .. how to go further... to create an application like VR CAVE. 
       
      Thanks
    • By cebugdev
      hi all,

      i am trying to build an OpenGL 2D GUI system, (yeah yeah, i know i should not be re inventing the wheel, but this is for educational and some other purpose only),
      i have built GUI system before using 2D systems such as that of HTML/JS canvas, but in 2D system, i can directly match a mouse coordinates to the actual graphic coordinates with additional computation for screen size/ratio/scale ofcourse.
      now i want to port it to OpenGL, i know that to render a 2D object in OpenGL we specify coordiantes in Clip space or use the orthographic projection, now heres what i need help about.
      1. what is the right way of rendering the GUI? is it thru drawing in clip space or switching to ortho projection?
      2. from screen coordinates (top left is 0,0 nd bottom right is width height), how can i map the mouse coordinates to OpenGL 2D so that mouse events such as button click works? In consideration ofcourse to the current screen/size dimension.
      3. when let say if the screen size/dimension is different, how to handle this? in my previous javascript 2D engine using canvas, i just have my working coordinates and then just perform the bitblk or copying my working canvas to screen canvas and scale the mouse coordinates from there, in OpenGL how to work on a multiple screen sizes (more like an OpenGL ES question).
      lastly, if you guys know any books, resources, links or tutorials that handle or discuss this, i found one with marekknows opengl game engine website but its not free,
      Just let me know. Did not have any luck finding resource in google for writing our own OpenGL GUI framework.
      IF there are no any available online, just let me know, what things do i need to look into for OpenGL and i will study them one by one to make it work.
      thank you, and looking forward to positive replies.
    • By fllwr0491
      I have a few beginner questions about tesselation that I really have no clue.
      The opengl wiki doesn't seem to talk anything about the details.
       
      What is the relationship between TCS layout out and TES layout in?
      How does the tesselator know how control points are organized?
          e.g. If TES input requests triangles, but TCS can output N vertices.
             What happens in this case?
      In this article,
      http://www.informit.com/articles/article.aspx?p=2120983
      the isoline example TCS out=4, but TES in=isoline.
      And gl_TessCoord is only a single one.
      So which ones are the control points?
      How are tesselator building primitives?
    • By Orella
      I've been developing a 2D Engine using SFML + ImGui.
      Here you can see an image
      The editor is rendered using ImGui and the scene window is a sf::RenderTexture where I draw the GameObjects and then is converted to ImGui::Image to render it in the editor.
      Now I need to create a 3D Engine during this year in my Bachelor Degree but using SDL2 + ImGui and I want to recreate what I did with the 2D Engine. 
      I've managed to render the editor like I did in the 2D Engine using this example that comes with ImGui. 
      3D Editor preview
      But I don't know how to create an equivalent of sf::RenderTexture in SDL2, so I can draw the 3D scene there and convert it to ImGui::Image to show it in the editor.
      If you can provide code will be better. And if you want me to provide any specific code tell me.
      Thanks!
  • Popular Now