I've been using alfont for a while and it worked just fine. but for some strange reason when i use it in conjunction with my GameEngine it doesn't want to load the fonts. What am I going to do!!!!
Certainly not get help, that's for sure.
You forgot to post what you were doing, your code, your error, or your versions.
I'm going to bet that it's a CWD problem.
sorry, just give me a moment to get the files.
| 1 | #include "GameEngine.h" |
| 2 | #include "alfont.h" |
| 3 | |
| 4 | int main() |
| 5 | { |
| 6 | allegro_init(); |
| 7 | install_keyboard(); |
| 8 | install_sound( DIGI_AUTODETECT, MIDI_AUTODETECT, NULL); |
| 9 | install_timer(); |
| 10 | if (install_mouse()==-1) |
| 11 | { |
| 12 | allegro_message("Unable to locate mouse! %s",allegro_error); |
| 13 | } |
| 14 | GameEngine GameEngine1; |
| 15 | GameEngine1.LockTimers(); |
| 16 | GameEngine1.SetSpeed(); |
| 17 | BITMAP*buffer; |
| 18 | ALFONT_FONT*font1; |
| 19 | set_color_depth(32); |
| 20 | if (set_gfx_mode(GFX_AUTODETECT,1280,1024,0,0)!=0) |
| 21 | { |
| 22 | if (set_gfx_mode(GFX_AUTODETECT,1280,960,0,0)!=0) |
| 23 | { |
| 24 | if (set_gfx_mode(GFX_AUTODETECT,1280,768,0,0)!=0) |
| 25 | { |
| 26 | if (set_gfx_mode(GFX_AUTODETECT,1280,720,0,0)!=0) |
| 27 | { |
| 28 | if (set_gfx_mode(GFX_AUTODETECT,1152,864,0,0)!=0) |
| 29 | { |
| 30 | if (set_gfx_mode(GFX_AUTODETECT,1024,768,0,0)!=0) |
| 31 | { |
| 32 | if (set_gfx_mode(GFX_AUTODETECT,800,600,0,0)!=0) |
| 33 | { |
| 34 | if (set_gfx_mode(GFX_AUTODETECT,640,480,0,0)!=0) |
| 35 | { |
| 36 | set_gfx_mode(GFX_TEXT,0,0,0,0); |
| 37 | allegro_message("Cannot initialize graphics mode! %s", allegro_error); |
| 38 | }//end the inner if statement |
| 39 | }//end the second to last if statement |
| 40 | }//end third to last if statement |
| 41 | }//end the fifth if statement |
| 42 | }//end the fourth if statement |
| 43 | }//end the third if statement |
| 44 | }//end the second if statement |
| 45 | }//ends the first statement |
| 46 | |
| 47 | |
| 48 | buffer=create_bitmap(SCREEN_W,SCREEN_H); |
| 49 | font1=alfont_load_font("Fonts/abaddon.ttf"); |
| 50 | if(!font1) |
| 51 | { |
| 52 | set_gfx_mode(GFX_TEXT,0,0,0,0); |
| 53 | allegro_message("No font"); |
| 54 | return -1; |
| 55 | } |
| 56 | alfont_textprintf_centre_ex(buffer,font1,SCREEN_W/2,SCREEN_H/2,makecol(160,200,160),-1,"Silver_Star_Games"); |
| 57 | while(!key[KEY_ESC]) |
| 58 | { |
| 59 | GameEngine1.draw_screen(buffer); |
| 60 | } |
| 61 | return 0; |
| 62 | }END_OF_MAIN(); |
this is my main file. It should work fine right.
Now you forgot to tell us the error.
I did tell you that it wont load the font didn't I? indirectly, I guess I should have been more clear. It says NO Font just like it's supposed to when it fails to load the font.
Okay, so does the file Fonts\abaddon.ttf exist? Where is it in relation to your EXE? How do you run the EXE?
The file does exist. It's in a Fonts folder along with the exe, well the exe is outside the fonts folder obviously. you understand. but like I said i've used this before and it worked just fine.
How do you run the EXE?
What if you add this code before you load the font:
if(!file_exists("Fonts/abaddon.ttf")) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("%s/Fonts/abaddon.ttf does not exist", getcwd(NULL, 1024)); } font1=alfont_load_font("Fonts/abaddon.ttf");
Ha haha..... I forgot to read the rest of this thread.
Ok. Your right. It says that the file doesn't exist. I know it does and the folder is there, why wont it recognise the file???
I need you to write down the way all of the folders in your project are laid out including the location of Fonts/abaddon.ttf and your exe. Then I need you to tell me how you run the exe.
Oh, and is the file accidentally named Fonts/abandon.ttf?
}//end the inner if statement }//end the second to last if statement }//end third to last if statement }//end the fifth if statement }//end the fourth if statement }//end the third if statement }//end the second if statement }//ends the first statement
Those are about the most worthless comments ever.
Ok everything os in a folder called GameEngine right. ok. from there we have all the header files(GameEngine.h)and the C++ files(GameEngine.cpp and Main.Cpp) the exe is in there aswell along with the makefile and the .o files(for GameEngine and main). Then theres another folder labeled Fonts, in there I have the font named abaddon.ttf. That's everything I have. I tried it with another font that I know works because it's the one I was using before but that wont work either.
BTW: BAF, shut up. I know their worthless, I copied it from a tutorial I made and didn't feel like deleting them.
And, like I've asked in my past 3 posts, how do you run the EXE?
Sorry, Uhhh. double click?! It's just an allegro win program. I don't know how to do anything special with it.
Dont need quite so many brackets
if (set_gfx_mode(GFX_AUTODETECT,1280,1024,0,0)!=0) if (set_gfx_mode(GFX_AUTODETECT,1280,960,0,0)!=0) if (set_gfx_mode(GFX_AUTODETECT,1280,768,0,0)!=0) if (set_gfx_mode(GFX_AUTODETECT,1280,720,0,0)!=0) if (set_gfx_mode(GFX_AUTODETECT,1152,864,0,0)!=0) if (set_gfx_mode(GFX_AUTODETECT,1024,768,0,0)!=0) if (set_gfx_mode(GFX_AUTODETECT,800,600,0,0)!=0) if (set_gfx_mode(GFX_AUTODETECT,640,480,0,0)!=0) { set_gfx_mode(GFX_TEXT,0,0,0,0); allegro_message("Cannot initialize graphics mode! %s", allegro_error); }
Will do
Okay, so when I gave you that code that told you the file didn't exist, was it looking at the right folder? I mean, when the message box comes up, press Ctrl+C to copy the text in it, then paste it here. Go to the folder that is in the path and tell me that abaddon.ttf is listed there.
---------------------------
game enginetest
---------------------------
E:\game stuff\Dev-Cpp\Game Engine/Fonts/abaddon.ttf does not exist
---------------------------
OK
---------------------------
That's where it is. I don't understand why it desnt work when I have another file
E:\game stuff\Dev-Cpp\YCPE/Fonts/abaddon.ttf
and that works just fine.
this is the file that abaddon.ttf is in
E:\game stuff\Dev-Cpp\Game Engine\Fonts
That's where it is.
According to your computer, you're wrong. It could be a permissions problem, but I'm almost certain that it isn't. If you go to the font file's properties and have a "security" tab, make sure that "Everyone" has "Read" access.
If that doesn't solve your problem, one of the following is true:
- The file abaddon.ttf really doesn't exist in E:\game stuff\Dev-Cpp\Game Engine\Fonts. You have to put it there.
- Your Allegro installation has become corrupt, for instance you have 2 different versions installed. You should completely remove all Allegro headers and DLLs and reinstall them.
[append]
Also, the second one is really unlikely unless you tried to install two different versions yourself, and the other Allegro program you have doesn't work also.
if (set_gfx_mode(GFX_AUTODETECT,1280,1024,0,0) || set_gfx_mode(GFX_AUTODETECT,1280,960,0,0) || set_gfx_mode(GFX_AUTODETECT,1280,768,0,0) || set_gfx_mode(GFX_AUTODETECT,1280,720,0,0) || set_gfx_mode(GFX_AUTODETECT,1152,864,0,0) || set_gfx_mode(GFX_AUTODETECT,1024,768,0,0) || set_gfx_mode(GFX_AUTODETECT,800,600,0,0) || set_gfx_mode(GFX_AUTODETECT,640,480,0,0)) { set_gfx_mode(GFX_TEXT,0,0,0,0); allegro_message("Cannot initialize graphics mode! %s", allegro_error); }
That should work fine too, and it doesn't look as ugly.
if (set_gfx_mode(GFX_AUTODETECT,1280,1024,0,0) || set_gfx_mode(GFX_AUTODETECT,1280,960,0,0) || set_gfx_mode(GFX_AUTODETECT,1280,768,0,0) || set_gfx_mode(GFX_AUTODETECT,1280,720,0,0) || set_gfx_mode(GFX_AUTODETECT,1152,864,0,0) || set_gfx_mode(GFX_AUTODETECT,1024,768,0,0) || set_gfx_mode(GFX_AUTODETECT,800,600,0,0) || set_gfx_mode(GFX_AUTODETECT,640,480,0,0)) { set_gfx_mode(GFX_TEXT,0,0,0,0); allegro_message("Cannot initialize graphics mode! %s", allegro_error); }
The question is, can you really depend on it short circuiting?
const int res[]={ 1280,1024, 1280,960, 1280,768, 1280,720, 1152,864, 1024,768, 800,600, 640,480 }; for(int i=0; i<18; i+=2) { if(i>16) { set_gfx_mode(GFX_TEXT,0,0,0,0); allegro_message("Cannot initialize graphics mode! %s", allegro_error); } else if(set_gfx_mode(GFX_AUTODETECT,res<i>,res[i+1],0,0)==0) break; }

Okay, I won't get this any further off topic. Promise.
Okay, I won't get this any further off topic.
But I will! It'd be better to get_gfx_mode_list.
Shouldn't this be under programming questions, since it's low-level rather than high-level?
OK. I figured it out and it's a real shame that we all missed it.
alfont_init();
that's it. That is all that was missing.
I copied it from a tutorial I made and didn't feel like deleting them.
What tutorial? Seriously, tell me. I need to know.
I havent put it online yet but when I do i'll let you know where to get it.8-)
If the rest of it looks like that, please don't unleash it upon the world...
I don't know if you care, because in any case, it works now, but:
The alfont_init didn't make it work, something else you changed did. Remember when we did this?
E:\game stuff\Dev-Cpp\Game Engine/Fonts/abaddon.ttf does not exist
file_exists is not dependent on alfont, so having not initialized alfont couldn't have been the problem.
The question is, can you really depend on it short circuiting?
Yes. The C standard mandates short-circuit logic.
What tutorial? Seriously, tell me. I need to know.
"Teach Yourself How Not To Do Things Right In 24 Hours"
Personally, I'd do:
| 1 | int init_gfx_mode() { |
| 2 | struct gfxmode { |
| 3 | int driver; |
| 4 | int w; |
| 5 | int h; |
| 6 | }; |
| 7 | |
| 8 | gfxmode gml[] = { |
| 9 | { GFX_AUTODETECT, 1280, 1024 }, |
| 10 | { GFX_AUTODETECT, 1280, 960 }, |
| 11 | // etc etc |
| 12 | { GFX_AUTODETECT, 640, 480 }, |
| 13 | { GFX_SAFE, 320, 200 }, |
| 14 | { 0, 0, 0 } |
| 15 | }; |
| 16 | |
| 17 | for (int i = 0; gml<i>.w, ++i) { |
| 18 | if (!set_gfx_mode(gml<i>.driver, gml<i>.w, gml<i>.h, 0, 0)) |
| 19 | return 0; |
| 20 | } |
| 21 | |
| 22 | return -1; |
| 23 | } |
...but that's just me.
Even when I got it to work, it said this file does not exist but then it continued with the program and loaded the font just fine.
The tutorial isn't meant to be the simplest and prettiest. It's meant for beginners to get a grasp of how the most basic of allegro functions work.
And if I said I haven't uploaded it yet, it probably means that i'm not done with it and i'm making changes. Have you tried to make any tutorials for other beginners? NO, then shut up, atleast i'm trying to help by sharing what knowlege I have.
Even when I got it to work, it said this file does not exist but then it continued with the program and loaded the font just fine.
Ah, you are correct. I misinterpreted the documentation for file_exists. It should read: file_exists("Fonts/abaddon.ttf", FA_ALL, NULL).
Have you tried to make any tutorials for other beginners? NO, then shut up, atleast i'm trying to help by sharing what knowlege I have.
You know what happens when you assume, right?
Yeah, the problems begin with that knowledge is misleading and contains horrible coding practices no one should ever be taught.
My bad, I was just trying to help some people who were in the same boat I once was; and obviously still am. So I added a few brackets, it's just to show how it's laid out. Other than that it really is just basic loading a Bitmap fron a file, loading a font( correctly, not anything to do with this thread), and displaying a few different things using a buffer. That's all. Sorry for making assumptions by the way.