Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » text won't render in iOS build

This thread is locked; no one can reply to it. rss feed Print
text won't render in iOS build
shpar0
Member #16,695
June 2017

Hi everyone,

I'm not very experienced and am trying to build a very simple app with some text scrolling around. I've managed to get the thing working quite well in the OSX build, but if I try to compile the same code for iOS, no text is rendered.

the following (just a hello world) compiles and runs (in the xcode iOS simulator) but does not render text, just colors the background:

#include <allegro5/allegro.h>
#include <allegro5/allegro_color.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
int main(void) {
al_init();
al_init_font_addon();
al_init_ttf_addon();

ALLEGRO_DISPLAY* display = al_create_display(640, 480);
ALLEGRO_FONT* font = al_load_font("/Library/Fonts/Futura.ttc", 40, NULL);

al_clear_to_color(al_color_html("#FF9900"));
al_draw_text(font, al_color_html("#EFEFEF"), 320, 200, ALLEGRO_ALIGN_CENTRE, "LOOK AT THIS!");
al_flip_display();
al_rest(5.0);
al_destroy_font(font);
al_destroy_display(display);

return 0;
}

if I build and run my original program (that's working fine on OSX) in the Xcode simulator it crashes and returns:

objc[11885]: Class PLBuildVersion is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x120b516f0) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x1206dfcc0). One of the two will be used. Which one is undefined.
testiramo8 was compiled with optimization - stepping may behave oddly; variables may not be available.

Is there something obvious I'm missing so that it wont even render text in the hello world one? I can provide the code for the program I'm working on, but it's basically just rendering scrolling text.

Thank you very much

SiegeLord
Member #7,827
October 2006
avatar

My guess is that the font isn't loading. Could you try commenting out the font related code and seeing if it at least displays the background? You can also use al_create_builtin_font instead of the TTF font to test with.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

shpar0
Member #16,695
June 2017

Thank you very much! using the built-in font both the hello world one and my original program work well on the simulator.

How should I go about finding out why normal fonts won't load? I presume some of the libraries I've linked in the iOS build project in Xcode aren't the right ones. I've had a lot of problems setting up the freetype libraries and I've been getting the following compiler errors with the freetype 2.8 ones:

dyld: Library not loaded: /usr/local/opt/freetype/lib/libfreetype.6.dylib
Referenced from: /Users/shpar/Library/Developer/CoreSimulator/Devices/0B463CAD-39D9-4453-BFFE-189DEDD59541/data/Containers/Bundle/Application/E52BBCFB-D01D-47E3-9DAC-BFAF27B3FF61/testiramo8.app/testiramo8
Reason: no suitable image found. Did find:
/usr/local/opt/freetype/lib/libfreetype.6.dylib: mach-o, but not built for iOS simulator

The linker gives the following: ld: warning: URGENT: building for iOS simulator, but linking against dylib (/usr/local/lib/libfreetype.dylib) built for OSX. Note: This will be an error in the future.

when using the old library from here (https://github.com/cdave1/freetype2-ios), it compiles but the ttf fonts won't render...

sorry, as I've said, amateur working on a hobby project

SiegeLord
Member #7,827
October 2006
avatar

There's two common failures when loading this in Allegro: the file isn't there or there's problem with the format. Assuming you got a functioning freetype (which appears to be the case if you're linking things right), the issue must be the file location. For iOS you basically always bundle your data inside your... bundle. You add an file copying build step and then just load your files using a relative path. There's probably a tutorial for this part somewhere.

You can check whether or not the actual file is there by doing al_fopen("your_file", "r"). If that returns NULL, then your problem is not TTF specific.

Almost certainly loading from /Library won't work though.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Go to: