11#include <GLFW/glfw3.h>
19 fprintf(stderr,
"GLFW Error %d: %s\n", error, description);
40 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
41 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
42 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
43 glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE);
45 m_window = glfwCreateWindow(width, height, title,
nullptr,
nullptr);
56 if (!gladLoadGL(glfwGetProcAddress))
58 fprintf(stderr,
"Failed to initialise OpenGL loader (glad)\n");
72 int iw = 0, ih = 0, ic = 0;
73 unsigned char* px =
nullptr;
77 wchar_t exePath[MAX_PATH]{};
78 GetModuleFileNameW(
nullptr, exePath, MAX_PATH);
79 auto iconPath = std::filesystem::path(exePath).parent_path() /
"wmv_16.png";
80 px = stbi_load(iconPath.string().c_str(), &iw, &ih, &ic, 4);
84 if (!px && fallbackPath)
85 px = stbi_load(fallbackPath, &iw, &ih, &ic, 4);
89 GLFWimage img{ iw, ih, px };
90 glfwSetWindowIcon(
m_window, 1, &img);
99 float xscale = 1.0f, yscale = 1.0f;
101 glfwGetWindowContentScale(
m_window, &xscale, &yscale);
102 return (xscale > yscale) ? xscale : yscale;
125 glfwSetWindowShouldClose(
m_window, GLFW_TRUE);
131 glfwGetFramebufferSize(
m_window, &w, &h);
void pollEvents()
Poll platform events (must be called once per frame).
void setIcon(const char *fallbackPath)
Load and set the window icon from a PNG file.
float queryDpiScale() const
Query the monitor content-scale (DPI).
void requestClose()
Signal the window to close.
static void errorCallback(int error, const char *description)
void framebufferSize(int &w, int &h) const
Retrieve the framebuffer size in pixels.
bool init(int width, int height, const char *title)
void swapBuffers()
Swap the front/back framebuffers.
bool shouldClose() const
Returns true when the user (or code) has requested the window to close.