Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Problem rendering TTF font (Allegro 5)

This thread is locked; no one can reply to it. rss feed Print
Problem rendering TTF font (Allegro 5)
Toumaz
Member #9,595
March 2008

I'm working on a small project using Allegro 5, and I've encountered a problem when rendering text using a TTF font under what seems like very specific circumstances.

Put simply, if I enable mipmapping and then try to draw text using a loaded TTF font, nothing seems to actually be drawn. The problem only occurs with TTF fonts (bitmap fonts work fine) and moreover, only while using the OpenGL driver (D3D works fine, too).

I'm using Allegro 5.0.0 RC3 with Visual Studio 2008 under Windows 7 64-bit. The graphics card is a NVIDIA GeForce 9800 GTX+, driver version 258.96.

I've tried reproducing it on a different computer under Ubuntu 10.04 32-bit, where drawing works both with and without mipmapping. I'm not very familiar with linux on the whole so I'm not certain what other information would be helpful, nor do I know offhand what hardware the machine has, aside from an ATI graphics card.

Here is a small test program I made along with a screenshot of the four test results. The resources used are from the examples bundled with Allegro 5.

#SelectExpand
1#include <allegro5/allegro.h> 2#include <allegro5/allegro_font.h> 3#include <allegro5/allegro_ttf.h> 4#include <allegro5/allegro_image.h> 5 6//#define USE_OPENGL 7//#define USE_MIPMAP 8 9int main() 10{ 11 al_init(); 12 al_install_keyboard(); 13 14#ifdef USE_OPENGL 15 al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_OPENGL); 16#else 17 al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_DIRECT3D_INTERNAL); 18#endif 19 20 ALLEGRO_DISPLAY* display = al_create_display(480, 128); 21 22#ifdef USE_OPENGL 23# ifdef USE_MIPMAP 24 al_set_window_title(display, "OpenGL (using mipmaps)"); 25# else 26 al_set_window_title(display, "OpenGL (no mipmaps)"); 27# endif 28#else 29# ifdef USE_MIPMAP 30 al_set_window_title(display, "D3D (using mipmaps)"); 31# else 32 al_set_window_title(display, "D3D (no mipmaps)"); 33# endif 34#endif 35 36 al_init_image_addon(); 37 al_init_font_addon(); 38 al_init_ttf_addon(); 39 40#ifdef USE_MIPMAP 41 al_set_new_bitmap_flags(al_get_new_bitmap_flags() | ALLEGRO_MIPMAP); 42#endif 43 44 ALLEGRO_FONT* font_ttf = al_load_font("DejaVuSans.ttf", 36, 0); 45 ALLEGRO_FONT* font_bmp = al_load_font("bmpfont.tga", 0, 0); 46 47 while (true) 48 { 49 ALLEGRO_KEYBOARD_STATE keyboard_state; 50 al_get_keyboard_state(&keyboard_state); 51 52 if (al_key_down(&keyboard_state, ALLEGRO_KEY_ESCAPE)) 53 break; 54 55 al_clear_to_color(al_map_rgb(128, 192, 225)); 56 57 al_draw_text(font_ttf, al_map_rgb(255, 255, 255), 10.0f, 10.0f, ALLEGRO_ALIGN_LEFT, "Lorem ipsum"); 58 al_draw_text(font_bmp, al_map_rgb(255, 255, 255), 10.0f, 60.0f, ALLEGRO_ALIGN_LEFT, "Lorem ipsum"); 59 60 al_flip_display(); 61 } 62 63 al_destroy_font(font_ttf); 64 al_destroy_font(font_bmp); 65 66 al_destroy_display(display); 67}

{"name":"Z9t9a.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/0\/20e3c6b616c8a07e430f4ff9b35e8dbc.png","w":496,"h":664,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/0\/20e3c6b616c8a07e430f4ff9b35e8dbc"}Z9t9a.png

Any help would be greatly appreciated.

Peter Wang
Member #23
April 2000

I can reproduce it here under Linux/nvidia. I'll try to look at it.

EDIT: Test this patch for me.

EDIT2: New patch.

Toumaz
Member #9,595
March 2008

That does seem to have done the trick - drawing works fine now. :)
Thanks a lot for the speedy response and for an excellent library!

Go to: