Skip to content

Instantly share code, notes, and snippets.

@kodai100
Created January 30, 2018 06:39
Show Gist options
  • Save kodai100/9a30f87f733efc8a9986382cfc134828 to your computer and use it in GitHub Desktop.
Save kodai100/9a30f87f733efc8a9986382cfc134828 to your computer and use it in GitHub Desktop.
For centering GLFW window
void centering(GLFWwindow* window) {
// Get screen resolution
const GLFWvidmode * mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
int screen_width = mode->width, screen_height = mode->height;
int halfx = screen_width / 2, halfy = screen_height / 2;
int hw = WIN_SIZE_X / 2, hh = WIN_SIZE_Y / 2;
int posx = halfx - hw, posy = halfy - hh;
glfwSetWindowPos(window, posx, posy);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment