Quick answer: Set version hints via glfwWindowHint before glfwCreateWindow. macOS requires forward-compatible core 3.2+; Windows defaults to compatibility.
A cross-platform game uses GLFW. Windows works; macOS crashes on glfwCreateWindow. macOS Cocoa won’t give pre-3.2 contexts.
Cross-Platform Hints
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
GLFWwindow* w = glfwCreateWindow(1280, 720, "Game", NULL, NULL);
Hints must come before CreateWindow. Core profile + forward compat is standard modern OpenGL.
Verify Context
glfwMakeContextCurrent(w);
printf("GL_VERSION: %s\n", glGetString(GL_VERSION));
Confirms what was created. If reports lower than requested, driver downgraded; investigate device support.
Error Callback
void glfwErrorCB(int code, const char* msg) {
fprintf(stderr, "GLFW error %d: %s\n", code, msg);
}
glfwSetErrorCallback(glfwErrorCB);
Detailed reason for CreateWindow failure. Without callback, you only see NULL return.
Headless Server
For dedicated server builds, skip windowing entirely. Don’t call glfwCreateWindow. Use OS-level signal/main loop.
Verifying
App opens on Win/Mac/Linux. GL version printed matches request or higher. No NULL returns.
“Hint before create, error callback for diagnostics, forward-compat on macOS. Three rules for cross-platform GLFW.”
For modern projects, consider Vulkan via GLFW — portable across all major platforms with one API rather than GL’s version maze.