From ef3a4c1ef63a8f1968a18eed4fcac3c91d314491 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Fri, 10 Jan 2014 00:04:39 +0100 Subject: [PATCH] First commit --- CMakeLists.txt | 31 +++++++++++++++++++ src/CloonelJumpConfig.h.in | 8 +++++ src/main.cpp | 63 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 src/CloonelJumpConfig.h.in create mode 100644 src/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..4c7f043 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 2.8) +project(CloonelJump CXX) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11") + +include(FindPkgConfig) +PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2) + +include_directories(SYSTEM + ${SDL2_INCLUDE_DIR} +) +include_directories( + src + include + "${PROJECT_BINARY_DIR}" +) + +configure_file( + "${PROJECT_SOURCE_DIR}/src/${PROJECT_NAME}Config.h.in" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.h" +) + +add_executable(${PROJECT_NAME} + src/main.cpp +) + +target_link_libraries(${PROJECT_NAME} + ${SDL2_LIBRARIES} +) diff --git a/src/CloonelJumpConfig.h.in b/src/CloonelJumpConfig.h.in new file mode 100644 index 0000000..944c582 --- /dev/null +++ b/src/CloonelJumpConfig.h.in @@ -0,0 +1,8 @@ +#ifndef id5FC1D6EEF9DF41E790068FBC6753035F +#define id5FC1D6EEF9DF41E790068FBC6753035F + +#define GameName "@PROJECT_NAME@" +#define GameVersionMinor 1 +#define GameVersionMajor 0 + +#endif diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..d79af39 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,63 @@ +#include +#include +#include "CloonelJumpConfig.h" +#include + +namespace { + struct InitSDLStuff { + SDL_Window* window; + SDL_Renderer* renderer; + bool initialized; + }; + + ///------------------------------------------------------------------------- + ///------------------------------------------------------------------------- + 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, 640, 480, SDL_WINDOW_SHOWN); + 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; + } + + ///------------------------------------------------------------------------- + ///------------------------------------------------------------------------- + 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 +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; +}