Day 83/100 100 Days of Code

Day 83/100 100 Days of Code

Jumping Ball

I created a new function for text rendering.

oid DisplayText(SDL_Renderer * renderer, TTF_Font *font, char* content, int x, int y)
{
    SDL_Color textColor = {0xff, 0xff, 0xff};
    SDL_Surface *textSurface = TTF_RenderText_Solid(font, content, textColor);

    if (textSurface == NULL)
    {
        printf("Failed to create surface: %s", SDL_GetError());
        exit(EXIT_FAILURE);
    }

    SDL_Texture *textTexture = SDL_CreateTextureFromSurface(renderer, textSurface);

    if (textTexture == NULL)
    {
        printf("Failed to create texture: %s", SDL_GetError());
        exit(EXIT_FAILURE);
    }

    float width = textSurface->w;
    float height = textSurface->h;

    const SDL_FRect textHolder = {x, y, width, height};
    SDL_RenderTexture(renderer, textTexture, NULL, &textHolder);

    SDL_DestroySurface(textSurface);
    textSurface = NULL;

    SDL_DestroyTexture(textTexture);
    textTexture = NULL;
}

Created a line to separate the window into 2 parts and created 2 new source files to handle the text box.

SDL_RenderLine(appRenderer, windowWidth/2, 0, windowWidth/2,  windowHeight);