diff options
author | stefonzo <stevester.robinson@gmail.com> | 2022-02-06 20:47:58 -0600 |
---|---|---|
committer | stefonzo <stevester.robinson@gmail.com> | 2022-02-06 20:47:58 -0600 |
commit | 4ebd9b8cf553359ebef8c8f8b2128e7b120bb251 (patch) | |
tree | db12692d5f36498e896c74d76323433ca28a69b3 /simple.cpp |
initial commit
Diffstat (limited to 'simple.cpp')
-rw-r--r-- | simple.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/simple.cpp b/simple.cpp new file mode 100644 index 0000000..5f5ab05 --- /dev/null +++ b/simple.cpp @@ -0,0 +1,42 @@ +#include "simple.hpp" +namespace simple { + simple::simple() { + startSDL(); + } + simple::~simple() { + closeSDL(); + } + void simple::startSDL() { + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + printf("SDL could not initialize! SDL Error: %s\n", SDL_GetError()); + } else { + mainWindow = SDL_CreateWindow("tbd", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 500, 500, SDL_WINDOW_SHOWN); + if (mainWindow == NULL) { + printf("Window could not be created! SDL Error: %s\n", SDL_GetError()); + } else { + mainRenderer = SDL_CreateRenderer(mainWindow, -1, SDL_RENDERER_ACCELERATED); + if (mainRenderer == NULL) { + printf("Renderer could not be created! SDL Error: %s\n", SDL_GetError()); + } else { + SDL_SetRenderDrawColor(mainRenderer, 0, 0, 0, 0); + int imgFlags = IMG_INIT_PNG; + if (!(IMG_Init(imgFlags) & imgFlags)) { + printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError()); + } else { + if (TTF_Init() == -1) { + printf("SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError()); + } + } + } + } + } + } + void simple::closeSDL() { + SDL_DestroyRenderer(mainRenderer); + SDL_DestroyWindow(mainWindow); + mainWindow = NULL; + TTF_Quit(); + IMG_Quit(); + SDL_Quit(); + } +} |