Browse Source

Move fullscreen to separate function, vsync to Context

master
Rick van Vonderen 5 years ago
parent
commit
859401ec24
  1. 2
      assets/settings.json
  2. 8
      inferno/src/inferno/render/context.cpp
  3. 68
      inferno/src/inferno/window.cpp
  4. 4
      inferno/src/inferno/window.h

2
assets/settings.json

@ -1,7 +1,9 @@
{
"window": {
"fullscreen": "windowed",
"height": 720,
"title": "Inferno",
"vsync": true,
"width": 1280
}
}

8
inferno/src/inferno/render/context.cpp

@ -26,8 +26,14 @@ namespace Inferno {
NF_CORE_INFO(" Renderer: %s", glGetString(GL_RENDERER));
NF_CORE_INFO(" Version: %s", glGetString(GL_VERSION));
// Set viewport
Window &w = *(Window*)glfwGetWindowUserPointer(m_window);
// Disable vsync
if (!w.isVSync()) {
glfwSwapInterval(0);
}
// Set viewport
glViewport(0, 0, w.getWidth(), w.getHeight());
// Enable z-buffer / depth buffer

68
inferno/src/inferno/window.cpp

@ -38,8 +38,6 @@ namespace Inferno {
const char* title = m_windowProperties.title;
unsigned int width = m_windowProperties.width;
unsigned int height = m_windowProperties.height;
const char* fullscreen = m_windowProperties.fullscreen;
bool vsync = m_windowProperties.vsync;
// Only init once
if (s_windowCount == 0) {
@ -47,43 +45,19 @@ namespace Inferno {
}
// Set window properties
// -----------------------------------------
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
// Windowed
GLFWmonitor* monitor = nullptr;
// Fullscreen
if (strcmp(fullscreen, "fullscreen") == 0) {
monitor = glfwGetPrimaryMonitor();
}
// Borderless fullscreen
if (strcmp(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 (!vsync) {
glfwWindowHint(GLFW_DOUBLEBUFFER, GL_FALSE);
}
// -----------------------------------------
// glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
// Create GLFW window
m_window = glfwCreateWindow(width, height, title, monitor, nullptr);
m_window = glfwCreateWindow(width, height, title, nullptr, nullptr);
s_windowCount++;
NF_CORE_ASSERT(m_window, "Failed to create GLFW window!");
// Set windowed/fullscreen/borderless
this->setWindowMonitor();
// Associate the wrapper to the window
glfwSetWindowUserPointer(m_window, this);
@ -199,4 +173,36 @@ namespace Inferno {
}
}
void Window::setWindowMonitor()
{
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
int xPos = 0;
int yPos = 0;
unsigned int width = m_windowProperties.width;
unsigned int height = m_windowProperties.height;
int refresh = GLFW_DONT_CARE;
const char* fullscreen = m_windowProperties.fullscreen;
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
if (strcmp(fullscreen, "windowed") == 0) {
monitor = nullptr;
// Put window in the center of the monitor
xPos = (mode->width - width) / 2;
yPos = (mode->height - height) / 2;
}
if (strcmp(fullscreen, "fullscreen") == 0) {
refresh = mode->refreshRate;
}
if (strcmp(fullscreen, "borderless") == 0) {
width = mode->width;
height = mode->height;
refresh = mode->refreshRate;
}
glfwSetWindowMonitor(m_window, monitor, xPos, yPos, width, height, refresh);
}
}

4
inferno/src/inferno/window.h

@ -30,8 +30,12 @@ namespace Inferno {
// -----------------------------------------
void setWindowMonitor();
inline int getWidth() const { return m_windowProperties.width; }
inline int getHeight() const { return m_windowProperties.height; }
inline bool isVSync() const { return m_windowProperties.vsync; }
inline GLFWwindow* getWindow() const { return m_window; }
inline void setEventCallback(std::function<void(Event&)> callback) { m_eventCallback = callback; }

Loading…
Cancel
Save