From 4ebd9b8cf553359ebef8c8f8b2128e7b120bb251 Mon Sep 17 00:00:00 2001 From: stefonzo Date: Sun, 6 Feb 2022 20:47:58 -0600 Subject: initial commit --- simple.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 simple.cpp (limited to 'simple.cpp') 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(); + } +} -- cgit v1.2.1