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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
#include "Init.h"
//global
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
//calls all other Initialization functions
void Init::initAll(SDL_Window* window, SDL_Renderer* renderer)
{
initVid();
initVSync();
initLinTextFilt();
initWindow(window);
initRenderer(window, renderer);
initTTF();
initIMG();
}
//Initialize SDL Video subsystem
bool Init::initVid()
{
bool success = true;
if(!SDL_Init(SDL_INIT_VIDEO) < 0)
{
printf("SDL_INIT_VIDEO failed. SDL Error: %s\n", SDL_GetError());
success = false;
}
return success;
}
//Initialize vertical synchronization
void Init::initVSync()
{
if(!SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1"))
{
printf("Warning: VSync not enabled.");
}
}
//initialize linear texture filtering
void Init::initLinTextFilt()
{
if(!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"))
{
printf("Warning: Linear texture filtering not enabled.");
}
}
//initialize window
bool Init::initWindow(SDL_Window* winArg)
{
bool success = true;
winArg = SDL_CreateWindow("Count++: Traffic Data Iterator", SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if(winArg == NULL)
{
printf("Window could not be created! SDL error: %s\n", SDL_GetError());
success = false;
}
return success;
}
//initialize renderer
bool Init::initRenderer(SDL_Window* winArg, SDL_Renderer* rendArg)
{
bool success = true;
rendArg = SDL_CreateRenderer(winArg, -1, SDL_RENDERER_ACCELERATED);
if(rendArg == NULL)
{
printf("Renderer could not be created! SDL error: %s\n", SDL_GetError());
success = false;
}
else
{
SDL_SetRenderDrawColor(rendArg, 0x00, 0x00, 0x00, 0xFF);
}
return success;
}
//Initialize TrueType Font subsystem
bool Init::initTTF()
{
bool success = true;
if( TTF_Init() == -1 )
{
printf( "SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError() );
success = false;
}
return success;
}
//Initialize PNG loading subsystem
bool Init::initIMG()
{
bool success = true;
int imgFlags = IMG_INIT_PNG;
if (!(IMG_Init(imgFlags)&imgFlags))
{
printf("SDL_Image could not initialize! SDL_Image Error: %s\n", IMG_GetError() );
success = false;
}
return success;
}
|