Search code examples
c++sdlfreetype

SDL: Initializng TTF problems. Possibly freetype?


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

Solution

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