rougier / freetype-gl

OpenGL text using one vertex buffer, one texture and FreeType
Other
1.65k stars 266 forks source link

Support for bitmap font types #157

Open agorgl opened 7 years ago

agorgl commented 7 years ago

Is it possible to add support for bitmap type fonts like pcf and bdf variants? As far as i know freetype already has drivers and loads fonts like these. You could use this font: http://font.gohu.org/ to test out the functionality

rougier commented 7 years ago

It might be possible without too much trouble if you first convert the font in ttf but I imagine this is not what you want ?

For small "debug" font, other techniques might be more suited, see for example https://github.com/glumpy/glumpy/blob/master/glumpy/app/console.py

It is in python, but if you look at the data array and the two shaders, this is all that is needed for fast and efficient display.

agorgl commented 7 years ago

Thanks for the alternative suggestion! I still would like to be able to use these type of fonts using freetype-gl. After changing the input font in "texture" demo initially i got "invalid module handle errors" initiating from the FT_Set_Char_Size call in texture_font_load_face function. When commenting the given call, the "texture" demo is able to compile and run, freetype loads and processes the pcf font without errors, but we get incorrect result (possibly some other kind of size setting function must be called in place for bitmap fonts?). Any ideas on this?

Update: Replacing the FT_Set_Char_Size with an FT_Select_Size call seems to populate the unpopulated face->size member used in texture_font_init function to set the metrics with sensible values without any freetype error (although the output is still incorrect).

rougier commented 7 years ago

But are bitmap fonts sizeable at all ?

agorgl commented 7 years ago

As far as i know they contain a specific set of sizes (most commonly just one), but why should that matter?

rougier commented 7 years ago

It would matter because the FT_Set_Char_Size would fail (I guess) and the computed size would be wrong. Instead, it would require to request the actual default size from the font and use it. Does that make sense?

agorgl commented 7 years ago

Yes, why not just do that? Detect if the font is of a scalable type or not and choose whether to set the size or query the default one. It will allow us to use bitmap fonts in the library without many significant changes.

rougier commented 7 years ago

Ok. Since you've already experienced with it, could you provide a PR?

agorgl commented 7 years ago

I'm messing around with it and i hope that i'll be able to make it work. I'll try to provide a PR.