summaryrefslogtreecommitdiff
path: root/simple.cpp
blob: 5f5ab05f90609f5a03eefbbee39aaea5f0988a22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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();
  }
}