tags:

views:

153

answers:

1

Edited: Look at comments below. Short version: Screen simply flashes when I try to run program.

int main(int argc, char** args)
{

    bool quit = false;

    std::ofstream out("error.txt");

    if(init() == false)
    {
        return 1;
    }

    if (load_files() == false)
    {
        return 1;
    }

    // Render the text
    message = TTF_RenderText_Solid(font, "The quick brown fox jumps over the lazy dog", textColor);

    // If there was an error in rendering the text
    if (message == NULL)
    {
        return 1;
    }

    // Apply the images to the screen
    apply_surface(0,0, background, screen);
    apply_surface(0,150, message, screen);

    // Update the screen
    if (SDL_Flip(screen) == -1)
    {
        std::cout << SDL_GetError() << '\n';
        return 1;
    }

    while (quit == false)
    {
        while (SDL_PollEvent(&event))
        {
            if (event.type == SDL_QUIT)
            {
                quit = true;
            }
        }
    }

    clean_up();

    return 0;
}
+1  A: 

What's the problem you're having? Is it failing to compile? Failing to link? Failing at program load time due to missing DLLs/shared libraries? Or failing at runtime?

Is screen NULL after the call to SDL_SetVideoMode()? If so, you should print out SDL_GetError(). If it is in fact TTF_Init() that is failing, then what is the error message that is printed?

Adam Rosenfield
Failing at runtime. I can't see an error message being printed because the screen just flashes and then goes away.
trikker
What platform? Are you running from the command line? Have you tried stepping through with a debugger?
Adam Rosenfield
Code::Blocks. It's simply an SDL project, build, compile, run. I know that TTF depends on FreeType2 to handle TrueType font data, I'm just not sure what to do with FreeType2 once it is installed. I've set include and linker paths. If there is something I'm missing, it would be setting a linker option (like -lSDL_image or -lSDL_ttf), but I'm not sure what the correct format is for FreeType.
trikker
I can't help you if you don't answer my questions -- what platform are you running on? Windows, OS X, Linux? Are you compiling with MSVC, MinGW, gcc, or something else? Are you running it by double-clicking it or running it from the command line? Have you tried stepping through with a debugger like MSVC or gdb?
Adam Rosenfield
MinGW, Windows, just compiling and running, I haven't used a debugger.
trikker
I also know that it is with the initialization function because in my main function if initialization fails it returns 1 and that is what I get.
trikker
I actually think now that I'm completely wrong in where the error is. I've done some testing by outputting fails into a file and so far I haven't gotten what I expected at all. The problem actually seems to be somewhere in my main function which I will post.
trikker
Solved. Was a syntax error.
trikker