-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
executable file
·157 lines (127 loc) · 4.2 KB
/
main.cpp
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_mixer.h>
#include <string>
#include "emainwindow.h"
#include "textures/egametextures.h"
#include "egamedir.h"
#include "enumbers.h"
bool init() {
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
printf("SDL could not initialize! SDL Error: %s\n",
SDL_GetError());
return false;
}
if(!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1")) {
printf("Warning: Linear texture filtering not enabled!");
}
const int imgFlags = IMG_INIT_PNG;
if(!(IMG_Init(imgFlags) & imgFlags)) {
printf("SDL_image could not initialize! SDL_image Error: %s\n",
IMG_GetError());
return false;
}
if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0) {
printf("SDL_mixer could not initialize! SDL_mixer Error: %s\n",
Mix_GetError());
return false;
}
if(TTF_Init()) {
printf("SDL_ttf could not initialize! SDL_ttf Error: %s\n",
TTF_GetError());
return false;
}
return true;
}
void close() {
TTF_Quit();
IMG_Quit();
Mix_Quit();
SDL_Quit();
}
bool getDisplayResolution(SDL_DisplayMode& mode) {
int display_count = 0, display_index = 0, mode_index = 0;
mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 };
if((display_count = SDL_GetNumVideoDisplays()) < 1) {
SDL_Log("SDL_GetNumVideoDisplays returned: %i", display_count);
return false;
}
if(SDL_GetDisplayMode(display_index, mode_index, &mode) != 0) {
SDL_Log("SDL_GetDisplayMode failed: %s", SDL_GetError());
return false;
}
SDL_Log("SDL_GetDisplayMode(0, 0, &mode):\t\t%i bpp\t%i x %i",
SDL_BITSPERPIXEL(mode.format), mode.w, mode.h);
return true;
}
bool getDisplayResolutions(std::vector<SDL_DisplayMode>& resolutions) {
const int display_count = SDL_GetNumVideoDisplays();
SDL_Log("Number of displays: %i", display_count);
for(int display_index = 0; display_index <= display_count; display_index++) {
SDL_Log("Display %i:", display_index);
const int modes_count = SDL_GetNumDisplayModes(display_index);
for(int mode_index = 0; mode_index <= modes_count; mode_index++) {
SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 };
if (SDL_GetDisplayMode(display_index, mode_index, &mode) == 0) {
SDL_Log(" %i bpp\t%i x %i @ %iHz",
SDL_BITSPERPIXEL(mode.format), mode.w, mode.h, mode.refresh_rate);
resolutions.push_back(mode);
}
}
}
return true;
}
int main() {
if(!init()) {
printf("Failed to initialize!\n");
close();
return 1;
}
eGameDir::initialize();
// SDL_DisplayMode mode;
// const bool r0 = getDisplayResolution(mode);
// eResolution resolution;
// if(r0) {
// resolution = eResolution(mode.w, mode.h);
// } else {
// resolution = eResolution(1280, 720);
// }
// std::vector<SDL_DisplayMode> resolutions;
// const bool r1 = getDisplayResolutions(resolutions);
// if(r1 && !resolutions.empty()) {
// eResolution::sResolutions = std::vector<eResolution>();
// for(const auto& m : resolutions) {
// eResolution::sResolutions.emplace_back(m.w, m.h);
// }
// }
std::vector<SDL_DisplayMode> ress;
const int displayCount = SDL_GetNumVideoDisplays();
for(int i = 0; i < displayCount; i++) {
SDL_DisplayMode dm;
SDL_GetCurrentDisplayMode(i, &dm);
bool contains = false;
for(const auto& rr : eResolution::sResolutions) {
contains = dm.w == rr.width() &&
dm.h == rr.height();
if(contains) break;
}
if(!contains) {
const auto res = eResolution(dm.w, dm.h);
eResolution::sResolutions.push_back(res);
}
}
eNumbers::sLoad();
eSettings settings;
settings.read();
eMainWindow w;
const bool i = w.initialize(settings);
if(!i) return 1;
const bool e = eGameTextures::initialize(w.renderer());
int r = 0;
if(e) {
r = w.exec();
}
close();
return r;
}