clooneljump/src/main.cpp

66 lines
2 KiB
C++
Raw Normal View History

2014-01-09 23:04:39 +00:00
#include <SDL2/SDL.h>
#include <iostream>
#include "CloonelJumpConfig.h"
#include <stdexcept>
namespace {
struct InitSDLStuff {
SDL_Window* window;
SDL_Renderer* renderer;
bool initialized;
};
///------------------------------------------------------------------------
///------------------------------------------------------------------------
2014-01-09 23:04:39 +00:00
void InitSDL (InitSDLStuff& parInitSDL) {
parInitSDL.window = nullptr;
parInitSDL.renderer = nullptr;
parInitSDL.initialized = false;
if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
throw std::runtime_error(SDL_GetError());
parInitSDL.initialized = true;
SDL_Window* const win = SDL_CreateWindow(GameName, 100, 100, DEF_WIN_WIDTH, DEF_WIN_HEIGHT, SDL_WINDOW_SHOWN);
2014-01-09 23:04:39 +00:00
if (!win)
throw std::runtime_error(SDL_GetError());
parInitSDL.window = win;
SDL_Renderer* const renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (!renderer)
throw std::runtime_error(SDL_GetError());
parInitSDL.renderer = renderer;
}
///------------------------------------------------------------------------
///------------------------------------------------------------------------
2014-01-09 23:04:39 +00:00
void ClearIFN (InitSDLStuff& parInitSDL) {
if (parInitSDL.renderer)
SDL_DestroyRenderer(parInitSDL.renderer);
if (parInitSDL.window)
SDL_DestroyWindow(parInitSDL.window);
if (parInitSDL.initialized)
SDL_Quit();
}
} //unnamed namespace
///----------------------------------------------------------------------------
///following http://twinklebeardev.blogspot.co.uk/2012/07/lesson-1-hello-world.html
///----------------------------------------------------------------------------
2014-01-09 23:04:39 +00:00
int main() {
std::cout << GameName << " v" << GameVersionMajor << "." << GameVersionMinor << std::endl;
InitSDLStuff sdlstuff;
try {
InitSDL(sdlstuff);
}
catch (const std::runtime_error& e) {
std::cerr << "Error during SDL2 initialization:\n";
std::cerr << e.what() << std::endl;
}
ClearIFN(sdlstuff);
std::cout << "Quitting now" << std::endl;
return 0;
}