Message Board


Message Board > C/C++ > SDL_ttf help & SDL program in linux opens then closes

September 23, 2012, 19:04
DoctorN
Whiskered
91 posts
1.
I am confused on getting the SDL_ttf to work. You can see in the .cpp files I have the ttf stuff set up, and it compiles without error, but I am not able to get the text to show. Can you fix it for me so I know what to do for every other thing later on? Thanks

2.
I use the commands in console:
Code:
g++ -o game main.cpp globals.cpp timer.cpp player.cpp -lSDL -lSDL_image -lSDL_ttf
chmod +x game
./game

The program is here: http://www.mediafire.com/?d2o6ccbq2t592d5

The program is put on the same drive as the OS itself, that is the answer I got from the previous thread. Anyways, the game compiles 100% I assume, and everything it needs has been installed. However, the second the game opens, it no sooner closes soon after that; on windows, it does not do that. It does print the two console commands I have in the very beginning of main.cpp. These are all the components I have installed:
Code:
yum install gcc gcc-c++ SDL-devel SDL_mixer-devel SDL_image-devel SDL_ttf-devel

and those installed the regular SDL's as well along with things like libpng and stuff like that. So, any help? Thanks
____________
#
September 24, 2012, 20:20
DTM
Earthling!
821 posts

Your files won't compile for me since you capitalize the #include file names e.g. "Player.h" yet the actual filenames are lower case. (Linux is case sensitive while Mac and maybe Windows too aren't).

SDL won't even install on my system so I can't help much there.

But if it does print something, then it is running, you just need to find out why it is closing.

You have stuff like this that will silently fail:
Code:
    if( init() == false )
    {
        return 1;
    }


If it fails, you should print an informative error message! Always!

Code:
    if( init() == false )
    {
        printf("Init failed.\n");
        return 1;
    }


Same in the init function and everywhere else, print some error messages, also print status messages when something succeeds:

Code:
    //Initialize all SDL subsystems
    if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
    {
        printf("SDL_Init failed!\n");
        return false;
    }

    printf("SDL Initialised successfully.\n");
   
    //Set up the screen
    screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );

    //If there was an error in setting up the screen
    if( screen == NULL )
    {
        printf("Setting up screen failed.\n");
        return false;
    }

    printf("Screen initialised\n");


Your task then is to pinpoint exactly what function call or line is failing.

[Edited on September 24, 2012 by DTM]
____________
:o
#
September 25, 2012, 04:26
DoctorN
Whiskered
91 posts
on windows that wasn't an issue and I did that on the linux thing but I guess I forgot to change that in the .zip file. Also the SDL\*.h files need to be SDL/*.h. I will boot up the program on linux now and see what is going on, I used your init check for the load files:
Code:
if( load_files() == false )
    {
        printf("Load failed.\n");
        return 1;
    }

and in the console I get load failed, and that is the last thing on the list. I don't know why its not loading. Thanks

EDIT: If I make //comment the return 1, when the thing loads up. Going further, the console tells me that player.png will not load.

EDIT2: Apparently .PNG was capitalized and linux for some reason is case sensitive so now it works.


NOW ONTO MY FIRST QUESTION, HOW DO I GET TTF WORKING?

[Edited on September 25, 2012 by DoctorN]
____________
#
September 26, 2012, 08:27
Dennis
どこかにいる
2092 posts

Try putting more printf in the load_files method, so you can actually trace which file(s) fail to load. Also check the privileges on the files you try to read.

Dennis.
____________
Kwakkel
#
September 27, 2012, 05:27
DoctorN
Whiskered
91 posts
I already got it to work. Now I need help with SDL_ttf
____________
#

Message Board > C/C++ > SDL_ttf help & SDL program in linux opens then closes

Quick reply


You must log in or register to post.
Copyright © 2005 Booleansoup.com
Questions? Comments? Bug reports? Contact us!