jak-project/game/graphics/display.cpp
water111 fe336b7b5f
[compiler] fix warnings in repl lib and add macros to autocomplete (#317)
* fix warnings in repl lib and add macros to autocomplete

* fix crash on ctrl-c, build runtime as static lib and make goos prompt look fancier

* some tweaks for linux build
2021-03-11 12:54:16 -05:00

55 lines
1.1 KiB
C++

/*!
* @file display.cpp
* Display for graphics. This is the game window, distinct from the runtime console.
*/
#include "display.h"
#include "common/log/log.h"
namespace Display {
GLFWwindow* display = NULL;
void InitDisplay(int width, int height, const char* title, GLFWwindow*& d) {
if (d) {
lg::warn("InitDisplay has already created a display window");
return;
}
// request OpenGL 3.0 (placeholder)
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
d = glfwCreateWindow(width, height, title, NULL, NULL);
if (!d) {
lg::error("InitDisplay failed - Could not create display window");
return;
}
glfwMakeContextCurrent(d);
if (!gladLoadGL()) {
lg::error("GL init fail");
KillDisplay(d);
return;
}
// enable vsync by default
glfwSwapInterval(1);
lg::debug("init display #x{}", (uintptr_t)d);
}
void KillDisplay(GLFWwindow*& d) {
lg::debug("kill display #x{}", (uintptr_t)d);
if (!d) {
lg::warn("KillDisplay called when no display was available");
return;
}
glfwDestroyWindow(d);
d = NULL;
}
} // namespace Display