Add fullscreen support
This commit is contained in:
parent
6a6dad4cdb
commit
b700ed3111
1 changed files with 19 additions and 0 deletions
19
src/main.cpp
19
src/main.cpp
|
@ -33,6 +33,7 @@ int windowX = SDL_WINDOWPOS_CENTERED;
|
||||||
int windowY = SDL_WINDOWPOS_CENTERED;
|
int windowY = SDL_WINDOWPOS_CENTERED;
|
||||||
int windowWidth = 640;
|
int windowWidth = 640;
|
||||||
int windowHeight = 480;
|
int windowHeight = 480;
|
||||||
|
int windowFullscreen = 0;
|
||||||
|
|
||||||
int toInt(const std::string &str) {
|
int toInt(const std::string &str) {
|
||||||
std::stringstream ss(str);
|
std::stringstream ss(str);
|
||||||
|
@ -62,6 +63,8 @@ void readConfig() {
|
||||||
windowWidth = toInt(value);
|
windowWidth = toInt(value);
|
||||||
} else if(key == "height") {
|
} else if(key == "height") {
|
||||||
windowHeight = toInt(value);
|
windowHeight = toInt(value);
|
||||||
|
} else if(key == "fullscreen") {
|
||||||
|
windowFullscreen = toInt(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,6 +84,8 @@ void writeConfig() {
|
||||||
|
|
||||||
file << "width=" << w << "\n";
|
file << "width=" << w << "\n";
|
||||||
file << "height=" << h << "\n";
|
file << "height=" << h << "\n";
|
||||||
|
|
||||||
|
file << "fullscreen=" << windowFullscreen << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int, char*[]) {
|
int main(int, char*[]) {
|
||||||
|
@ -96,6 +101,8 @@ int main(int, char*[]) {
|
||||||
if(!window)
|
if(!window)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
SDL_SetWindowFullscreen(window, windowFullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
|
||||||
|
|
||||||
Renderer* renderer = new Renderer();
|
Renderer* renderer = new Renderer();
|
||||||
|
|
||||||
VkSurfaceKHR surface = nullptr;
|
VkSurfaceKHR surface = nullptr;
|
||||||
|
@ -139,6 +146,18 @@ int main(int, char*[]) {
|
||||||
if(event.window.event == SDL_WINDOWEVENT_RESIZED)
|
if(event.window.event == SDL_WINDOWEVENT_RESIZED)
|
||||||
target = renderer->createSurfaceRenderTarget(surface, target);
|
target = renderer->createSurfaceRenderTarget(surface, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(event.type == SDL_KEYDOWN && event.key.keysym.scancode == SDL_SCANCODE_F11) {
|
||||||
|
if(windowFullscreen == 1) {
|
||||||
|
SDL_SetWindowFullscreen(window, 0);
|
||||||
|
windowFullscreen = 0;
|
||||||
|
} else {
|
||||||
|
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||||
|
windowFullscreen = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
target = renderer->createSurfaceRenderTarget(surface, target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer->render(world, target);
|
renderer->render(world, target);
|
||||||
|
|
Reference in a new issue