-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cc
74 lines (62 loc) · 1.87 KB
/
main.cc
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
/*
* Copyright (C) YEAR NAME
*
* This file is part of FIXME_NAME.
*
* FIXME_NAME is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FIXME_NAME is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with FIXME_NAME. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <string>
#include <SDL2/SDL.h>
#include <SDL2pp/SDL.hh>
#include <SDL2pp/Window.hh>
#include <SDL2pp/Renderer.hh>
int main(int /*argc*/, char** /*argv*/) try {
// SDL stuff
SDL2pp::SDL sdl(SDL_INIT_VIDEO);
SDL2pp::Window window("FIXME_TITLE", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_RESIZABLE);
SDL2pp::Renderer renderer(window, -1, SDL_RENDERER_ACCELERATED);
unsigned int prev_ticks = SDL_GetTicks();
// Main loop
while (1) {
unsigned int frame_ticks = SDL_GetTicks();
unsigned int frame_delta = frame_ticks - prev_ticks;
prev_ticks = frame_ticks;
// Process events
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
return 0;
} else if (event.type == SDL_KEYDOWN) {
switch (event.key.keysym.sym) {
case SDLK_ESCAPE: case SDLK_q:
return 0;
}
}
}
// Render
renderer.SetDrawColor(0, 0, 0);
renderer.Clear();
renderer.Present();
// Frame limiter
SDL_Delay(1);
}
return 0;
} catch (std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
} catch (...) {
std::cerr << "Unknown error" << std::endl;
return 1;
}