Results 1 to 8 of 8

Thread: Win32 native fonts: CreateFont vs FreeType

  1. #1
    Lesser Knight
    Join Date
    Aug 2008
    Location
    Folsom, California USA
    Posts
    37

    Default Win32 native fonts: CreateFont vs FreeType

    I think I'm almost there with my changes to enable third-party windowing library integration as described in the "Clanlib on Fltk", but I've run into one final roadblock that I need some consensus on.

    I found that the CL_GraphicContext class has a Win32-only accessor: HDC get_drawable(). This is a bit of a problem for me, since I've been busily eliminating explicit references to the underlying platform-specific handles supplied by the window provider types in favor of a generic interface that can wrap other third-party providers. Now, I could hack in special support for this by requiring that adapter type to be able to provide an HDC on Win32, but it seems kludgy.

    I've determined that the only place this special accessor is used appears to be in Win32 native font support. Creating fonts via Win32 API requires a DC. The problem is, this introduces a platform dependency and an assumption that there is a particular kind of window provider underneath. So, I'm trying to see if there's a way around this without having to hack in platform-specific accessors into what should be a platform-agnostic type.

    My first thought is: since Clanlib is already using FreeType on Linux, is there any reason we don't want to just use FreeType all around for native fonts? In addition to solving my little problem, it would also have the advantage of helping to standardize font parameters and rendering; given the same TTF and parameters, fonts should come out much more consistently across platforms if it was always FreeType doing the rendering. We were actually just talking about getting away from Win32-specific font conventions in the "Linux Fonts" thread.

    So, does using FreeType on Win32 as well as Linux/Mac seem like a good idea?

    --- Kevin

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    I added get_drawable() - it is a nasty hack, and i was meaning to remove it. ... so i will

    The reason that we use native fonts on windows is because it looks so much nicer

  3. #3
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    get_drawable() has now been removed from CL_GraphicContext API

    I have just updated Freetype to v2.3.7 "All users should upgrade" ( http://www.freetype.org/index2.html#...freetype-2.3.7 )

    And it looks a LOT nicer. However the String Height reports an incorrect value

    ... Investigating...

    ... Fixed (simple bug)

    Attached is a linux screengrab.

    Compare this with the windows one (found at http://www.rtsoft.com/forums/attachm...5&d=1221120855 )

    It is getting a lot better
    Attached Images Attached Images  
    Last edited by rombust; 09-22-2008 at 09:19 AM. Reason: update and screen grab

  4. #4
    Lesser Knight
    Join Date
    Aug 2008
    Location
    Folsom, California USA
    Posts
    37

    Default

    > get_drawable() has now been removed from CL_GraphicContext API

    Thanks, that's a big help.

    I wonder how the fonts would compare if Linux and Win32 were actually using the same TTF? I'll have to get the "free" MS fonts installed on Ubuntu and see how it compares.

    Installing the 'msttcorefonts' package is easy, and gets you a variety of MS fonts including the ubiquitous Arial and Times New Roman, but not the infamous Tahoma. Its crazy the extra trouble the Debian people had to undertake to observe MS's arbitrary requirement that the "filename or packaging format" must not be changed. "To promote cross-platform compatibility"... yeah, right.

    Hmm, it appears that fontconfig picked up the new fonts, but FreeType seems to be munging them a bit on antialiasing. Not quite sure what to make of this; could this be an effect of the "patent-free" hinting? This computer has the Ubuntu packaged libfreetype6 v.2.3.5 installed.

    --- Kevin
    Attached Images Attached Images  

  5. #5
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    At some point we probably should allow games to use freetype on Windows without trouble (or do we allow that easilly already?).

    It is basically conflicting interests - when you are doing normal GUI apps you want the native font rasterizer for the platform, so you avoid the 'Safari looks weird on Windows' effect when all fonts in your app is rendered slightly different than everything else. On the other hand, a game really wants to look the same everywhere for artistic reasons, so a game would probably prefer using the freetype implementation on all platforms.

  6. #6
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Kevin, that screenshot is how it used to look on my ubuntu.

    Today, through the package manager, there was an update to freetype, but i think that was was 2.3.5. I did not try it, instead I downloaded the latest one (from http://www.freetype.org )

    When compiling it, i had to download the latest version of libtools (to run ./autogen.sh) and I compiled it using "./configure --prefix=/usr", but I am unsure if the prefix if required. (remember to sudo make install)

    It should be very easy to make it optional for windows - to use either method (freetype or native). I'm not too sure whether to add a "use_native_font" flag to CL_Font, or create a CL_FontFreeType_Provider, like CL_FontBitmap_Provider - probably the latter would be nicer.
    Last edited by rombust; 09-22-2008 at 09:27 PM. Reason: Spelling

  7. #7
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    I have changed the fonts in ClanLib SVN as follows:

    1) All Sources/API/Display/Render/*font*.* moved into Sources/API/Display/Font

    2) Split CL_FontProvider_Native into 2 classes: CL_FontProvider_Freetype and CL_FontProvider_Win32

    3) Modified CL_OpenGLGraphicContextProvider::alloc_font() to create CL_FontProvider_Win32() for Windows Platform and CL_FontProvider_Freetype() for others Platforms

    To use CL_Font_Freetype on the Win32 platform, you should be able to do:

    Code:
    	CL_Font_Freetype font("Resources/font.ttf", 32);
    	CL_Font old_font = gc.set_font(font);
    	gc.draw_text(0, 300, cl_text("Hello World"),  CL_Colorf::white);
    	gc.set_font(old_font);
    To use CL_Font_Freetype with the GUI, you should be able to do:

    Code:
    	CL_GUIManager gui;
    	...
    	CL_Font_Freetype font("Resources/font.ttf", 32);
    	gui.set_named_font(&font, "ClanLib Font", 32);
    	...
    	(Use "ClanLib Font" as the font name")
    Very nice i think

    This should work for Dicewar as well. If satisfactory, then "CL_OpenGLGraphicContextProvider::register_fon t()" can be removed.

    *REMEMBER* To use the latest FreeType 2.3.7 for the windows platform, else the results will be terrible !

  8. #8
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    Very nice, Mark.

    I guess DiceWar should always use freetype - now we just need someone to volunteer compiling it for MSVC9

Similar Threads

  1. WIN32 ClanLib 0.9 Message Queue has_messages()
    By rombust in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 09-15-2008, 06:01 PM
  2. my fonts are really grainy
    By babyvegas in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 07-11-2008, 04:07 PM
  3. ClanLib gui and fonts
    By LonelyStar in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 04-28-2008, 07:52 AM
  4. Python as a win32 gaming platform
    By jjohn in forum Game development
    Replies: 1
    Last Post: 03-09-2007, 02:42 AM
  5. Fonts & Graphics
    By AllenJB in forum Game development
    Replies: 1
    Last Post: 09-16-2006, 12:00 AM

Bookmarks

Bookmarks

Posting Permissions

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