init and ttf
This commit is contained in:
parent
e39c7dc647
commit
ca535d4a70
@ -8,6 +8,7 @@ if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
|
|||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
find_package(SDL2 CONFIG REQUIRED)
|
find_package(SDL2 CONFIG REQUIRED)
|
||||||
|
find_package(SDL2_ttf CONFIG REQUIRED)
|
||||||
find_package(CURL REQUIRED)
|
find_package(CURL REQUIRED)
|
||||||
|
|
||||||
add_executable(hang_man src/main.cpp
|
add_executable(hang_man src/main.cpp
|
||||||
@ -21,5 +22,6 @@ add_executable(hang_man src/main.cpp
|
|||||||
target_link_libraries(hang_man PRIVATE
|
target_link_libraries(hang_man PRIVATE
|
||||||
SDL2::SDL2
|
SDL2::SDL2
|
||||||
SDL2::SDL2main
|
SDL2::SDL2main
|
||||||
|
SDL2_ttf::SDL2_ttf
|
||||||
CURL::libcurl
|
CURL::libcurl
|
||||||
)
|
)
|
||||||
|
30
src/Game.cpp
30
src/Game.cpp
@ -1,7 +1,35 @@
|
|||||||
|
#include <iostream>
|
||||||
#include "Game.hpp"
|
#include "Game.hpp"
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
#include "SDL_ttf.h"
|
||||||
|
|
||||||
void Game::Run() {
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL_rect.h>
|
||||||
|
|
||||||
|
const SDL_Point SCREEN_SIZE{800, 800};
|
||||||
|
|
||||||
class Game {
|
class Game {
|
||||||
|
|
||||||
|
@ -6,9 +6,12 @@
|
|||||||
"dependencies": [
|
"dependencies": [
|
||||||
{
|
{
|
||||||
"name": "sdl2",
|
"name": "sdl2",
|
||||||
"default-features": true,
|
"features": [
|
||||||
|
"vulkan"
|
||||||
|
],
|
||||||
"version>=": "2.0.20"
|
"version>=": "2.0.20"
|
||||||
},
|
},
|
||||||
|
"sdl2-ttf",
|
||||||
"curl"
|
"curl"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user