init and ttf

This commit is contained in:
Love 2024-08-02 15:29:51 +02:00
parent e39c7dc647
commit ca535d4a70
4 changed files with 38 additions and 2 deletions

View File

@ -8,6 +8,7 @@ if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
endif ()
find_package(SDL2 CONFIG REQUIRED)
find_package(SDL2_ttf CONFIG REQUIRED)
find_package(CURL REQUIRED)
add_executable(hang_man src/main.cpp
@ -21,5 +22,6 @@ add_executable(hang_man src/main.cpp
target_link_libraries(hang_man PRIVATE
SDL2::SDL2
SDL2::SDL2main
SDL2_ttf::SDL2_ttf
CURL::libcurl
)

View File

@ -1,7 +1,35 @@
#include <iostream>
#include "Game.hpp"
#include "SDL.h"
#include "SDL_ttf.h"
void Game::Run() {
SDL_
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << "Failed to initialize SDL: " << SDL_GetError() << std::endl;
exit(-1);
}
if (TTF_Init() < 0) {
std::cerr << "Failed to initialize TTF: " << TTF_GetError() << std::endl;
exit(-1);
}
SDL_Window *window = SDL_CreateWindow("hang man", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_SIZE.x,
SCREEN_SIZE.y, 0);
if (window == nullptr) {
std::cerr << "Failed to create SDL_Window with error: " << SDL_GetError() << std::endl;
exit(-1);
}
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (renderer == nullptr) {
std::cerr << "Failed to create SDL_Renderer with error: " << SDL_GetError() << std::endl;
exit(-1);
}
SDL_RendererInfo rendererInfo;
if (SDL_GetRendererInfo(renderer, &rendererInfo) == 0) {
std::cout << "Using renderer: " << rendererInfo.name << std::endl;
}
SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
}

View File

@ -1,5 +1,8 @@
#pragma once
#include <SDL_rect.h>
const SDL_Point SCREEN_SIZE{800, 800};
class Game {

View File

@ -6,9 +6,12 @@
"dependencies": [
{
"name": "sdl2",
"default-features": true,
"features": [
"vulkan"
],
"version>=": "2.0.20"
},
"sdl2-ttf",
"curl"
]
}