I'm using OpenGLUT functions like glutBitmapString to render sentences and words in a game. However, there is a limited set of fonts to use and I need some bigger size fonts. Is there a way to add new fonts to these functions/API?



Try Freetype OpenGL, a library for displaying a unicode text using a (single) vertex buffer and freetype fonts. Have a look at their web, repository and documentation.

An example, from their website:

    /* Text to be printed */
    wchar_t *text = L"A Quick Brown Fox Jumps Over The Lazy Dog 0123456789";

    /* Texture atlas to store individual glyphs */
    texture_atlas_t *atlas = texture_atlas_new( 512, 512, 1 );

    /* Build a new texture font from its description and size */
    texture_font_t *font = texture_font_new( atlas, "./Vera.ttf", 16 );

   /* Build a new vertex buffer (position, texture & color) */
    vertex_buffer_t *buffer= vertex_buffer_new( "v3i:t2f:c4f" );

    /* Cache some glyphs to speed things up */
    texture_font_load_glyphs( font, L" !\"#$%&'()*+,-./0123456789:;<=>?"

    /* Where to start printing on screen */
    vec2 pen = {0,0};
    vec4 black = {0,0,0,1};

   /* Add text tothe buffer (see demo-font.c for the add_text code) */
    add_text( buffer, font, "Hello World !", text, &black, &pen );
  • \$\begingroup\$ It is extremely hard to install freetype-gl. I use Ubuntu. Full of mysterious installation obstacles. \$\endgroup\$
    – ar2015
    Sep 16 '17 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.