获取显示屏的个数和分辨率 — 通过使用OpenGL的GLFW库
程序
#include <iostream>
// GLFW
#include <GLFW/glfw3.h>
int main()
{
// Init GLFW
glfwInit();
// Set all the required options for GLFW
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
int monitorCount;
//GLFWmonitor* pMonitor = glfwGetPrimaryMonitor();
GLFWmonitor** pMonitor = glfwGetMonitors(&monitorCount);
std::cout << "Now, Screen number is " << monitorCount << std::endl;
for(int i=0; i<monitorCount; i++){
int screen_x, screen_y;
const GLFWvidmode * mode = glfwGetVideoMode(pMonitor[i]);
std::cout << "Screen size is X = " << mode->width << ", Y = " << mode->height << std::endl;
}
//waiting
getchar();
// Terminate GLFW, clearing any resources allocated by GLFW.
glfwTerminate();
return 0;
}
运行程序
Now, Screen number is 2
Screen size is X = 1920, Y = 1080
Screen size is X = 1280, Y = 1024
参考网站:
http://gamedev.stackexchange.com/questions/60244/how-to-find-monitor-resolution-with-glfw3
http://geistyp.weebly.com/tech-life/080-glfw