Implement fullscreen/vsync into Window and Settings
This commit is contained in:
@@ -32,6 +32,8 @@ namespace Inferno {
|
|||||||
m_properties.title = strdup(m_json["window"]["title"].get<std::string>().c_str());
|
m_properties.title = strdup(m_json["window"]["title"].get<std::string>().c_str());
|
||||||
m_properties.width = m_json["window"]["width"].get<int>();
|
m_properties.width = m_json["window"]["width"].get<int>();
|
||||||
m_properties.height = m_json["window"]["height"].get<int>();
|
m_properties.height = m_json["window"]["height"].get<int>();
|
||||||
|
m_properties.fullscreen = strdup(m_json["window"]["fullscreen"].get<std::string>().c_str());
|
||||||
|
m_properties.vsync = m_json["window"]["vsync"].get<bool>();
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
NF_CORE_WARN("Settings syntax error: using default values");
|
NF_CORE_WARN("Settings syntax error: using default values");
|
||||||
@@ -42,6 +44,7 @@ namespace Inferno {
|
|||||||
{
|
{
|
||||||
// Delete const char*s created by strdup()
|
// Delete const char*s created by strdup()
|
||||||
delete m_properties.title;
|
delete m_properties.title;
|
||||||
|
delete m_properties.fullscreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json Settings::load() const
|
nlohmann::json Settings::load() const
|
||||||
@@ -68,6 +71,8 @@ namespace Inferno {
|
|||||||
json["window"]["title"] = m_properties.title;
|
json["window"]["title"] = m_properties.title;
|
||||||
json["window"]["width"] = m_properties.width;
|
json["window"]["width"] = m_properties.width;
|
||||||
json["window"]["height"] = m_properties.height;
|
json["window"]["height"] = m_properties.height;
|
||||||
|
json["window"]["fullscreen"] = m_properties.fullscreen;
|
||||||
|
json["window"]["vsync"] = m_properties.vsync;
|
||||||
|
|
||||||
std::ofstream file (m_path);
|
std::ofstream file (m_path);
|
||||||
NF_CORE_ASSERT(file.is_open(), "Could not open settings file!");
|
NF_CORE_ASSERT(file.is_open(), "Could not open settings file!");
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ namespace Inferno {
|
|||||||
const char* title = "Inferno default";
|
const char* title = "Inferno default";
|
||||||
unsigned int width = 1280;
|
unsigned int width = 1280;
|
||||||
unsigned int height = 720;
|
unsigned int height = 720;
|
||||||
|
const char* fullscreen = "windowed"; // windowed/fullscreen/borderless
|
||||||
|
bool vsync = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Settings {
|
class Settings {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include <cstring>
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
#include "inferno/core.h"
|
#include "inferno/core.h"
|
||||||
@@ -41,13 +43,40 @@ namespace Inferno {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set window properties
|
// Set window properties
|
||||||
|
// -----------------------------------------
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
||||||
|
|
||||||
|
// Windowed
|
||||||
|
GLFWmonitor* monitor = nullptr;
|
||||||
|
// Fullscreen
|
||||||
|
if (strcmp(Settings::get().properties().fullscreen, "fullscreen") == 0) {
|
||||||
|
monitor = glfwGetPrimaryMonitor();
|
||||||
|
}
|
||||||
|
// Borderless fullscreen
|
||||||
|
if (strcmp(Settings::get().properties().fullscreen, "borderless") == 0) {
|
||||||
|
monitor = glfwGetPrimaryMonitor();
|
||||||
|
|
||||||
|
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
||||||
|
width = mode->width;
|
||||||
|
height = mode->height;
|
||||||
|
|
||||||
|
glfwWindowHint(GLFW_RED_BITS, mode->redBits);
|
||||||
|
glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
|
||||||
|
glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
|
||||||
|
glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vsync
|
||||||
|
if (!Settings::get().properties().vsync) {
|
||||||
|
glfwWindowHint(GLFW_DOUBLEBUFFER, GL_FALSE);
|
||||||
|
}
|
||||||
|
// -----------------------------------------
|
||||||
|
|
||||||
// Create GLFW window
|
// Create GLFW window
|
||||||
m_window = glfwCreateWindow(width, height, title, NULL, NULL);
|
m_window = glfwCreateWindow(width, height, title, monitor, nullptr);
|
||||||
s_windowCount++;
|
s_windowCount++;
|
||||||
NF_CORE_ASSERT(m_window, "Failed to create GLFW window!");
|
NF_CORE_ASSERT(m_window, "Failed to create GLFW window!");
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ namespace Inferno {
|
|||||||
const char* title = "Inferno";
|
const char* title = "Inferno";
|
||||||
unsigned int width = 1280;
|
unsigned int width = 1280;
|
||||||
unsigned int height = 720;
|
unsigned int height = 720;
|
||||||
|
const char* fullscreen = "windowed"; // windowed/fullscreen/borderless
|
||||||
|
bool vsync = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Window {
|
class Window {
|
||||||
|
|||||||
Reference in New Issue
Block a user