First commit
This commit is contained in:
commit
ef3a4c1ef6
3 changed files with 102 additions and 0 deletions
31
CMakeLists.txt
Normal file
31
CMakeLists.txt
Normal file
|
@ -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}
|
||||||
|
)
|
8
src/CloonelJumpConfig.h.in
Normal file
8
src/CloonelJumpConfig.h.in
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef id5FC1D6EEF9DF41E790068FBC6753035F
|
||||||
|
#define id5FC1D6EEF9DF41E790068FBC6753035F
|
||||||
|
|
||||||
|
#define GameName "@PROJECT_NAME@"
|
||||||
|
#define GameVersionMinor 1
|
||||||
|
#define GameVersionMajor 0
|
||||||
|
|
||||||
|
#endif
|
63
src/main.cpp
Normal file
63
src/main.cpp
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "CloonelJumpConfig.h"
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
Loading…
Reference in a new issue