您的位置:首页 > 运维架构

获取显示屏的个数和分辨率 --- 通过使用OpenGL的GLFW库

2016-07-13 03:37 477 查看

获取显示屏的个数和分辨率 — 通过使用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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息