Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » AGUI Help: Can't load font

This thread is locked; no one can reply to it. rss feed Print
AGUI Help: Can't load font
Restful Cargo
Member #16,106
October 2015

I am having trouble getting AGUI to work on a simple allegro menu example and was wondering if anyone could give me some advice (besides trying a different library). I am not sure if this is the correct forum to post this but if it isn't then have the mods delete the thread. Hopefully the author is still around?

The code sample at the end of this message compiles and links, but it explodes as soon as it calls function "agui::Font::load". I tried using different font files and copying it to different locations, but no success.

My code copies agui routines straight from the "agui_example.cpp" in the Agui-0.2.-1 distribution (which ironically works and loads the font just fine). Using Visual Studio 2013 with the pre-compiled allegro-msvc2013-x86-5.1.12 binaries.

Appreciate any help I could get. Thank you for your time.

#SelectExpand
1#include <cstdio> 2#include <string> 3#include <allegro5/allegro.h> 4#include <allegro5/allegro_native_dialog.h> 5 6 7#include <Agui/Agui.hpp> 8#include <Agui/Backends/Allegro5/Allegro5.hpp> 9 10#include <Agui/Widgets/Button/Button.hpp> 11#include <Agui/Widgets/CheckBox/CheckBox.hpp> 12#include <Agui/Widgets/DropDown/DropDown.hpp> 13#include <Agui/Widgets/TextField/TextField.hpp> 14#include <Agui/Widgets/Frame/Frame.hpp> 15#include <Agui/Widgets/RadioButton/RadioButton.hpp> 16#include <Agui/Widgets/RadioButton/RadioButtonGroup.hpp> 17#include <Agui/Widgets/Slider/Slider.hpp> 18#include <Agui/Widgets/TextBox/ExtendedTextBox.hpp> 19#include <Agui/Widgets/Tab/TabbedPane.hpp> 20#include <Agui/Widgets/ListBox/ListBox.hpp> 21#include <Agui/Widgets/ScrollPane/ScrollPane.hpp> 22#include <Agui/FlowLayout.hpp> 23 24 25enum enum_menu{ 26 FILE_ID = 1, 27 FILE_OPEN_ID, 28 FILE_RESIZE_ID, 29 FILE_FULLSCREEN_ID, 30 FILE_CLOSE_ID, 31 FILE_EXIT_ID, 32 OPTIONS_ID, 33 OPTIONS_INPUT_ID, 34 HELP_ABOUT_ID 35}; 36 37ALLEGRO_MENU_INFO main_menu_info[] = { 38 ALLEGRO_START_OF_MENU("&File", FILE_ID), 39 { "&Open", FILE_OPEN_ID, 0, NULL }, 40 ALLEGRO_MENU_SEPARATOR, 41 { "E&xit", FILE_EXIT_ID, 0, NULL }, 42 ALLEGRO_END_OF_MENU, 43 ALLEGRO_START_OF_MENU("&Options", OPTIONS_ID), 44 { "&Input", OPTIONS_INPUT_ID, 0, NULL }, 45 ALLEGRO_END_OF_MENU 46 47}; 48 49ALLEGRO_DISPLAY *g_display = NULL; 50ALLEGRO_MENU *g_menu; 51ALLEGRO_EVENT_QUEUE *g_queue; 52ALLEGRO_EVENT g_event; 53bool bQuitFlag = false; 54 55agui::Gui *gui = NULL; 56agui::Allegro5Input* inputHandler = NULL; 57agui::Allegro5Graphics* graphicsHandler = NULL; 58 59agui::Font *defaultFont = NULL; 60 61 62class SimpleActionListener : public agui::ActionListener 63{ 64public: 65 virtual void actionPerformed(const agui::ActionEvent &evt) 66 { 67 agui::Slider* slider = dynamic_cast<agui::Slider*>(evt.getSource()); 68 if (slider) 69 { 70 slider->setBackColor(agui::Color(slider->getValue(), slider->getValue(), slider->getValue())); 71 return; 72 73 } 74 al_show_native_message_box(al_get_current_display(), 75 "Agui Action Listener", 76 "", 77 "An Action Event has occured!", 78 NULL, NULL); 79 } 80}; 81 82class WidgetCreator { 83private: 84 SimpleActionListener simpleAL; 85 agui::FlowLayout flow; 86 agui::Button button; 87 agui::CheckBox checkBox; 88 agui::DropDown dropDown; 89 agui::TextField textField; 90 agui::Frame frame; 91 agui::Gui* mGui; 92 agui::RadioButton rButton[3]; 93 agui::RadioButtonGroup rGroup; 94 agui::Slider slider; 95 agui::ExtendedTextBox exTextBox; 96 agui::TabbedPane tabbedPane; 97 agui::Tab tab[3]; 98 agui::ListBox listBox; 99 agui::ScrollPane scrollPane; 100 agui::Button scrollButtons[15]; 101 102public: 103 WidgetCreator(agui::Gui *guiInstance) 104 { 105 mGui = guiInstance; 106 mGui->add(&flow); 107 flow.add(&button); 108 button.setSize(80, 40); 109 button.setText("Push Me"); 110 button.addActionListener(&simpleAL); 111 112 113 } 114}; 115 116void initializeAgui() 117{ 118 119 //Set the image loader 120 //agui::Image::setImageLoader(new agui::Allegro5ImageLoader); 121 122 //Set the font loader 123 agui::Font::setFontLoader(new agui::Allegro5FontLoader); 124 125 //Instance the input handler 126 inputHandler = new agui::Allegro5Input(); 127 128 //Instance the graphics handler 129 graphicsHandler = new agui::Allegro5Graphics(); 130 131 //Allegro does not automatically premultiply alpha so let Agui do it 132 agui::Color::setPremultiplyAlpha(true); 133 134 //Instance the gui 135 gui = new agui::Gui(); 136 137 //Set the input handler 138 gui->setInput(inputHandler); 139 140 //Set the graphics handler 141 gui->setGraphics(graphicsHandler); 142 143/////////////////////////////////////////////////////////////// 144 145 defaultFont = agui::Font::load("DejaVuSans.ttf", 16); // <--- CRASHES HERE 146 147/////////////////////////////////////////////////////////////// 148 149 //Setting a global font is required and failure to do so will crash. 150 agui::Widget::setGlobalFont(defaultFont); 151 152} 153 154WidgetCreator* creator; 155 156void do_menu() 157{ 158 if (g_event.user.data2 == (intptr_t)g_display) 159 { 160 switch (g_event.user.data1) 161 { 162 case (HELP_ABOUT_ID) : 163 { 164 break; 165 } 166 case (FILE_OPEN_ID) : 167 { 168 169 170 171 break; 172 } 173 case (FILE_EXIT_ID) : 174 { 175 bQuitFlag = true; 176 break; 177 } 178 case OPTIONS_INPUT_ID: 179 { 180 181 break; 182 } 183 } // end switch 184 185 } 186 187} 188 189int main(int argc, char *argv[]) 190{ 191 192 al_init(); 193 al_install_keyboard(); 194 195 g_display = al_create_display(320, 200); 196 al_clear_to_color(al_map_rgb(0, 0, 0)); 197 198 /* not checking init failures for simplicity */ 199 200 if (al_init_native_dialog_addon()) 201 { 202 g_menu = al_build_menu(main_menu_info); 203 if (g_menu) 204 { 205 if (al_set_display_menu(g_display, g_menu)) 206 { 207 initializeAgui(); 208 209 g_queue = al_create_event_queue(); 210 if (g_queue) 211 { 212 al_register_event_source(g_queue, al_get_display_event_source(g_display)); 213 al_register_event_source(g_queue, al_get_keyboard_event_source()); 214 al_register_event_source(g_queue, al_get_default_menu_event_source()); 215 216 } 217 218 } 219 220 } 221 222 } 223 224 while (!bQuitFlag) 225 { 226 if (!al_is_event_queue_empty(g_queue)) 227 { 228 al_get_next_event(g_queue, &g_event); 229 { 230 switch (g_event.type) 231 { 232 case ALLEGRO_EVENT_DISPLAY_CLOSE: 233 { 234 bQuitFlag = true; 235 break; 236 } 237 case ALLEGRO_EVENT_MENU_CLICK: 238 { 239 do_menu(); 240 break; 241 } 242 case ALLEGRO_EVENT_KEY_DOWN: 243 { 244 if (g_event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) 245 bQuitFlag = true; 246 break; 247 } 248 249 } // end switch 250 } // end case 251 } // end if 252 253 al_flip_display(); 254 255 } // end while 256 257 return 0; 258}

jmasterx
Member #11,410
October 2009

I see
al_init();
al_install_keyboard();

But I dont see you init the other addons... Look at all the addons the example inits: https://github.com/jmasterx/Agui/blob/master/example/agui_example_a5.cpp#L270

Restful Cargo
Member #16,106
October 2015

I see. I didn't initialize the necessary allegro routines. Thank you.

Go to: