Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Ha haha..... I'm having trouble with alfont.

Credits go to CGamesPlay for helping out!
This thread is locked; no one can reply to it. rss feed Print
 1   2 
Ha haha..... I'm having trouble with alfont.
Taiko Keiji
Member #8,307
February 2007
avatar

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!!!!

Life could be better, machines could program themselves.

Taiko Keiji-
http://lostotaku.net

CGamesPlay
Member #2,559
July 2002
avatar

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.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Taiko Keiji
Member #8,307
February 2007
avatar

sorry, just give me a moment to get the files.

1#include "GameEngine.h"
2#include "alfont.h"
3 
4int 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.

Life could be better, machines could program themselves.

Taiko Keiji-
http://lostotaku.net

CGamesPlay
Member #2,559
July 2002
avatar

Now you forgot to tell us the error.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Taiko Keiji
Member #8,307
February 2007
avatar

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.

Life could be better, machines could program themselves.

Taiko Keiji-
http://lostotaku.net

CGamesPlay
Member #2,559
July 2002
avatar

Okay, so does the file Fonts\abaddon.ttf exist? Where is it in relation to your EXE? How do you run the EXE?

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Taiko Keiji
Member #8,307
February 2007
avatar

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.

Life could be better, machines could program themselves.

Taiko Keiji-
http://lostotaku.net

CGamesPlay
Member #2,559
July 2002
avatar

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");

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Onewing
Member #6,152
August 2005
avatar

Ha haha..... I forgot to read the rest of this thread.

------------
Solo-Games.org | My Tech Blog: The Digital Helm

Taiko Keiji
Member #8,307
February 2007
avatar

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???

Life could be better, machines could program themselves.

Taiko Keiji-
http://lostotaku.net

CGamesPlay
Member #2,559
July 2002
avatar

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?

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

BAF
Member #2,981
December 2002
avatar

Quote:

                                }//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. :P

Taiko Keiji
Member #8,307
February 2007
avatar

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.

Life could be better, machines could program themselves.

Taiko Keiji-
http://lostotaku.net

CGamesPlay
Member #2,559
July 2002
avatar

And, like I've asked in my past 3 posts, how do you run the EXE?

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Taiko Keiji
Member #8,307
February 2007
avatar

Sorry, Uhhh. double click?! It's just an allegro win program. I don't know how to do anything special with it.

Life could be better, machines could program themselves.

Taiko Keiji-
http://lostotaku.net

Ceagon Xylas
Member #5,495
February 2005
avatar

Dont need quite so many brackets :P

     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

CGamesPlay
Member #2,559
July 2002
avatar

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.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Taiko Keiji
Member #8,307
February 2007
avatar

---------------------------
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

Life could be better, machines could program themselves.

Taiko Keiji-
http://lostotaku.net

CGamesPlay
Member #2,559
July 2002
avatar

Quote:

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.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

BAF
Member #2,981
December 2002
avatar

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. :P

Onewing
Member #6,152
August 2005
avatar

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?

------------
Solo-Games.org | My Tech Blog: The Digital Helm

Ceagon Xylas
Member #5,495
February 2005
avatar

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;
}

:-X
Okay, I won't get this any further off topic. Promise.

Onewing
Member #6,152
August 2005
avatar

Quote:

Okay, I won't get this any further off topic.

But I will! It'd be better to get_gfx_mode_list.

------------
Solo-Games.org | My Tech Blog: The Digital Helm

Kibiz0r
Member #6,203
September 2005
avatar

Shouldn't this be under programming questions, since it's low-level rather than high-level?

Taiko Keiji
Member #8,307
February 2007
avatar

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.

Life could be better, machines could program themselves.

Taiko Keiji-
http://lostotaku.net

 1   2 


Go to: