in body-tracking-samples/sample_helper_libs/window_controller_3d/WindowController3d.cpp [62:183]
void WindowController3d::Create(const char* name, bool showWindow, int width, int height, bool fullscreen)
{
CheckAssert(!m_initialized);
m_initialized = true;
// Should be called in main
GLFWEnvironmentSingleton::InitGLFW();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
if (!showWindow)
{
glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
}
const GLFWvidmode* displayInfo = glfwGetVideoMode(glfwGetPrimaryMonitor());
if (width <= 0 || height <= 0)
{
m_windowWidth = static_cast<int>(displayInfo->width * m_defaultWindowWidthRatio);
m_windowHeight = static_cast<int>(displayInfo->height * m_defaultWindowHeightRatio);
}
else
{
m_windowWidth = width;
m_windowHeight = height;
}
m_windowStartPositionX = (displayInfo->width - m_windowWidth) / 2;
m_windowStartPositionY = (displayInfo->height - m_windowHeight) / 2;
// Get monitor for full screen
GLFWmonitor* monitor = nullptr;
if (fullscreen)
{
monitor = glfwGetPrimaryMonitor();
int modesCount = 0, bestMode = 0;
auto modes = glfwGetVideoModes(monitor, &modesCount);
for (int i = 0; i < modesCount; i++)
{
if (modes[i].width >= modes[bestMode].width
|| modes[i].height >= modes[bestMode].height
|| modes[i].refreshRate >= modes[bestMode].refreshRate
|| (modes[i].blueBits + modes[i].greenBits + modes[i].redBits) >= (modes[bestMode].blueBits + modes[bestMode].greenBits + modes[bestMode].redBits))
{
bestMode = i;
}
}
m_windowWidth = modes[bestMode].width;
m_windowHeight = modes[bestMode].height;
}
// Create window
m_window = glfwCreateWindow(m_windowWidth, m_windowHeight, name, monitor, nullptr);
if (!m_window)
{
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwSetWindowPos(m_window, m_windowStartPositionX, m_windowStartPositionY);
// In to use the member function as callback, set the current class as the Window User Pointer
glfwSetWindowUserPointer(m_window, this);
// Set all callbacks
auto windowCloseCallback = [](GLFWwindow *window) {
static_cast<WindowController3d *>(glfwGetWindowUserPointer(window))->
WindowCloseCallback(window);
};
glfwSetWindowCloseCallback(m_window, windowCloseCallback);
auto windowResizeCallback = [](GLFWwindow *window, int w, int h) {
static_cast<WindowController3d *>(glfwGetWindowUserPointer(window))->
FrameBufferSizeCallback(window, w, h);
};
glfwSetFramebufferSizeCallback(m_window, windowResizeCallback);
auto keyPressCallback = [](GLFWwindow* window, int key, int scancode, int action, int mods) {
static_cast<WindowController3d *>(glfwGetWindowUserPointer(window))->
KeyPressCallback(window, key, scancode, action, mods);
};
glfwSetKeyCallback(m_window, keyPressCallback);
auto mouseMovementCallback = [](GLFWwindow *window, double xpos, double ypos) {
static_cast<WindowController3d *>(glfwGetWindowUserPointer(window))->
MouseMovementCallback(window, xpos, ypos);
};
glfwSetCursorPosCallback(m_window, mouseMovementCallback);
auto mouseScrollCallback = [](GLFWwindow *window, double xoffset, double yoffset) {
static_cast<WindowController3d *>(glfwGetWindowUserPointer(window))->
MouseScrollCallback(window, xoffset, yoffset);
};
glfwSetScrollCallback(m_window, mouseScrollCallback);
auto mouseButtonCallback = [](GLFWwindow *window, int button, int action, int mods) {
static_cast<WindowController3d *>(glfwGetWindowUserPointer(window))->
MouseButtonCallback(window, button, action, mods);
};
glfwSetMouseButtonCallback(m_window, mouseButtonCallback);
glfwMakeContextCurrent(m_window);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwSwapInterval(showWindow ? 1 : 0);
// Context Settings
glEnable(GL_MULTISAMPLE);
glDisable(GL_BLEND);
glClearColor(0.f, 0.f, 0.f, 0.f);
glClearDepth(1.0f);
m_pointCloudRenderer.Create(m_window);
m_skeletonRenderer.Create(m_window);
}