open font

This commit is contained in:
Love 2024-08-03 10:57:53 +02:00
parent cf7a9a1f1a
commit 91328c4aca
2 changed files with 24 additions and 3 deletions

View File

@ -1,11 +1,13 @@
#include <iostream>
#include <algorithm>
#include <random>
#include <sstream>
#include "Game.hpp"
#include "SDL.h"
#include "SDL_ttf.h"
#include "words.hpp"
#include "utils.hpp"
#include "default_font.hpp"
const int CHAR_SIZE = 30;
const int STEP_SIZE = CHAR_SIZE + CHAR_SIZE / 2;
@ -65,6 +67,23 @@ void Game::Run() {
}
Game::Game() {
const char *defaultFontPath = getDefaultFontPath();
if (defaultFontPath == nullptr) {
std::stringstream ss;
ss << "Font path is not set for this platform (null)";
auto s = ss.str();
std::cerr << s << std::endl;
throw std::runtime_error(s);
}
font = TTF_OpenFont(defaultFontPath, CHAR_SIZE);
if (font == nullptr) {
std::stringstream ss;
ss << "Failed to load font: " << TTF_GetError();
auto s = ss.str();
std::cerr << s << std::endl;
throw std::runtime_error(s);
}
std::random_device random_device{};
std::mt19937 rng(random_device());

View File

@ -1,10 +1,11 @@
#pragma once
#include <SDL_rect.h>
#include <SDL_events.h>
#include <vector>
#include <optional>
#include <SDL_render.h>
#include "SDL_rect.h"
#include "SDL_events.h"
#include "SDL_render.h"
#include "SDL_ttf.h"
#include "GuessCorrector.hpp"
const SDL_Point SCREEN_SIZE{800, 800};
@ -14,6 +15,7 @@ private:
std::vector<const char *> all_words;
std::unique_ptr<GuessCorrector> guess_corrector;
const char *word;
const _TTF_Font *font;
public:
static void Run();