2012-03-08 00:01:42 +00:00
|
|
|
//========================================================================
|
2015-01-25 22:37:29 +00:00
|
|
|
// Monitor information tool
|
2016-11-21 15:23:59 +00:00
|
|
|
// Copyright (c) Camilla Löwy <elmindreda@glfw.org>
|
2012-03-08 00:01:42 +00:00
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied
|
|
|
|
// warranty. In no event will the authors be held liable for any damages
|
|
|
|
// arising from the use of this software.
|
|
|
|
//
|
|
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
|
|
// including commercial applications, and to alter it and redistribute it
|
|
|
|
// freely, subject to the following restrictions:
|
|
|
|
//
|
|
|
|
// 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
// claim that you wrote the original software. If you use this software
|
|
|
|
// in a product, an acknowledgment in the product documentation would
|
|
|
|
// be appreciated but is not required.
|
|
|
|
//
|
|
|
|
// 2. Altered source versions must be plainly marked as such, and must not
|
|
|
|
// be misrepresented as being the original software.
|
|
|
|
//
|
|
|
|
// 3. This notice may not be removed or altered from any source
|
|
|
|
// distribution.
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
//
|
2015-01-25 22:37:29 +00:00
|
|
|
// This test prints monitor and video mode information or verifies video
|
|
|
|
// modes
|
2012-03-08 00:01:42 +00:00
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
|
2021-08-24 23:18:03 +00:00
|
|
|
#define GLAD_GL_IMPLEMENTATION
|
2019-04-14 15:34:38 +00:00
|
|
|
#include <glad/gl.h>
|
2019-05-24 15:17:15 +00:00
|
|
|
#define GLFW_INCLUDE_NONE
|
2013-05-22 20:46:34 +00:00
|
|
|
#include <GLFW/glfw3.h>
|
2012-03-08 00:01:42 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2012-05-06 23:13:07 +00:00
|
|
|
#include <string.h>
|
2012-03-08 00:01:42 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "getopt.h"
|
|
|
|
|
|
|
|
enum Mode
|
|
|
|
{
|
2023-03-03 12:20:35 +00:00
|
|
|
LIST_MODE_OLD,
|
2012-03-08 00:01:42 +00:00
|
|
|
LIST_MODE,
|
|
|
|
TEST_MODE
|
|
|
|
};
|
|
|
|
|
|
|
|
static void usage(void)
|
|
|
|
{
|
2015-01-25 22:37:29 +00:00
|
|
|
printf("Usage: monitors [-t]\n");
|
|
|
|
printf(" monitors -h\n");
|
2012-03-08 00:01:42 +00:00
|
|
|
}
|
|
|
|
|
2016-09-30 01:44:13 +00:00
|
|
|
static int euclid(int a, int b)
|
|
|
|
{
|
|
|
|
return b ? euclid(b, a % b) : a;
|
|
|
|
}
|
|
|
|
|
2012-12-02 20:18:01 +00:00
|
|
|
static const char* format_mode(const GLFWvidmode* mode)
|
2012-03-08 00:01:42 +00:00
|
|
|
{
|
2012-05-06 23:30:55 +00:00
|
|
|
static char buffer[512];
|
2016-09-30 01:44:13 +00:00
|
|
|
const int gcd = euclid(mode->width, mode->height);
|
2012-05-06 23:30:55 +00:00
|
|
|
|
2016-09-30 03:31:07 +00:00
|
|
|
snprintf(buffer,
|
|
|
|
sizeof(buffer),
|
|
|
|
"%i x %i x %i (%i:%i) (%i %i %i) %i Hz",
|
|
|
|
mode->width, mode->height,
|
|
|
|
mode->redBits + mode->greenBits + mode->blueBits,
|
|
|
|
mode->width / gcd, mode->height / gcd,
|
|
|
|
mode->redBits, mode->greenBits, mode->blueBits,
|
|
|
|
mode->refreshRate);
|
2012-05-06 23:30:55 +00:00
|
|
|
|
|
|
|
buffer[sizeof(buffer) - 1] = '\0';
|
|
|
|
return buffer;
|
2012-03-08 00:01:42 +00:00
|
|
|
}
|
|
|
|
|
2023-03-03 12:20:35 +00:00
|
|
|
static const char* format_mode2(const GLFWvideoMode* mode)
|
|
|
|
{
|
|
|
|
int width, height;
|
|
|
|
int r, g, b;
|
|
|
|
float rate;
|
|
|
|
|
|
|
|
glfwVideoModeGetSize(mode, &width, &height);
|
|
|
|
glfwVideoModeGetColorDepth(mode, &r, &g, &b);
|
|
|
|
rate = glfwVideoModeGetRefreshRate(mode);
|
|
|
|
|
|
|
|
static char buffer[512];
|
|
|
|
const int gcd = euclid(width, height);
|
|
|
|
|
|
|
|
snprintf(buffer,
|
|
|
|
sizeof(buffer),
|
|
|
|
"%i x %i x %i (%i:%i) (%i %i %i) %f Hz",
|
|
|
|
width, height,
|
|
|
|
r + g + b,
|
|
|
|
width / gcd, height / gcd,
|
|
|
|
r, g, b,
|
|
|
|
rate);
|
|
|
|
|
|
|
|
buffer[sizeof(buffer) - 1] = '\0';
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2012-03-08 00:01:42 +00:00
|
|
|
static void error_callback(int error, const char* description)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Error: %s\n", description);
|
|
|
|
}
|
|
|
|
|
2013-06-03 10:51:57 +00:00
|
|
|
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
2012-03-08 00:01:42 +00:00
|
|
|
{
|
2013-06-03 10:51:57 +00:00
|
|
|
printf("Framebuffer resized to %ix%i\n", width, height);
|
2012-03-08 00:01:42 +00:00
|
|
|
|
|
|
|
glViewport(0, 0, width, height);
|
|
|
|
}
|
|
|
|
|
2013-05-30 15:19:12 +00:00
|
|
|
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
2012-05-06 22:44:39 +00:00
|
|
|
{
|
|
|
|
if (key == GLFW_KEY_ESCAPE)
|
2015-08-23 17:30:04 +00:00
|
|
|
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
2012-05-06 22:44:39 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 20:13:28 +00:00
|
|
|
static void list_modes(GLFWmonitor* monitor)
|
2012-05-06 23:12:08 +00:00
|
|
|
{
|
2017-08-29 17:19:00 +00:00
|
|
|
int count, x, y, width_mm, height_mm, i;
|
2018-09-08 14:38:43 +00:00
|
|
|
int workarea_x, workarea_y, workarea_width, workarea_height;
|
2017-08-29 17:19:00 +00:00
|
|
|
float xscale, yscale;
|
2018-09-08 14:38:43 +00:00
|
|
|
|
2013-05-22 20:16:43 +00:00
|
|
|
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
2012-12-02 20:18:01 +00:00
|
|
|
const GLFWvidmode* modes = glfwGetVideoModes(monitor, &count);
|
2012-05-06 23:12:08 +00:00
|
|
|
|
2013-01-24 18:10:17 +00:00
|
|
|
glfwGetMonitorPos(monitor, &x, &y);
|
2017-08-29 17:19:00 +00:00
|
|
|
glfwGetMonitorPhysicalSize(monitor, &width_mm, &height_mm);
|
|
|
|
glfwGetMonitorContentScale(monitor, &xscale, &yscale);
|
2018-09-08 14:38:43 +00:00
|
|
|
glfwGetMonitorWorkarea(monitor, &workarea_x, &workarea_y, &workarea_width, &workarea_height);
|
2013-01-24 18:10:17 +00:00
|
|
|
|
2012-12-22 22:37:42 +00:00
|
|
|
printf("Name: %s (%s)\n",
|
|
|
|
glfwGetMonitorName(monitor),
|
|
|
|
glfwGetPrimaryMonitor() == monitor ? "primary" : "secondary");
|
2013-05-22 20:16:43 +00:00
|
|
|
printf("Current mode: %s\n", format_mode(mode));
|
2019-10-10 16:03:28 +00:00
|
|
|
printf("Virtual position: %i, %i\n", x, y);
|
|
|
|
printf("Content scale: %f x %f\n", xscale, yscale);
|
2012-10-18 21:09:28 +00:00
|
|
|
|
2019-10-10 16:03:28 +00:00
|
|
|
printf("Physical size: %i x %i mm (%0.2f dpi at %i x %i)\n",
|
|
|
|
width_mm, height_mm, mode->width * 25.4f / width_mm, mode->width, mode->height);
|
|
|
|
printf("Monitor work area: %i x %i starting at %i, %i\n",
|
|
|
|
workarea_width, workarea_height, workarea_x, workarea_y);
|
2012-05-06 22:32:03 +00:00
|
|
|
|
2012-08-30 00:12:02 +00:00
|
|
|
printf("Modes:\n");
|
|
|
|
|
2012-03-08 00:01:42 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2012-05-06 23:30:55 +00:00
|
|
|
printf("%3u: %s", (unsigned int) i, format_mode(modes + i));
|
2012-05-06 23:13:07 +00:00
|
|
|
|
2013-05-29 20:35:58 +00:00
|
|
|
if (memcmp(mode, modes + i, sizeof(GLFWvidmode)) == 0)
|
2012-08-29 23:53:23 +00:00
|
|
|
printf(" (current mode)");
|
2012-05-06 23:13:07 +00:00
|
|
|
|
2012-03-08 00:01:42 +00:00
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-03 12:20:35 +00:00
|
|
|
static void list_modes2(GLFWmonitor* monitor)
|
|
|
|
{
|
|
|
|
int width, height;
|
|
|
|
int count, x, y, width_mm, height_mm, i;
|
|
|
|
int workarea_x, workarea_y, workarea_width, workarea_height;
|
|
|
|
float xscale, yscale;
|
|
|
|
|
|
|
|
const GLFWvideoMode* mode = glfwGetVideoMode2(monitor);
|
|
|
|
const GLFWvideoMode* const* modes = glfwGetVideoModes2(monitor, &count);
|
|
|
|
|
|
|
|
glfwGetMonitorPos(monitor, &x, &y);
|
|
|
|
glfwGetMonitorPhysicalSize(monitor, &width_mm, &height_mm);
|
|
|
|
glfwGetMonitorContentScale(monitor, &xscale, &yscale);
|
|
|
|
glfwGetMonitorWorkarea(monitor, &workarea_x, &workarea_y, &workarea_width, &workarea_height);
|
|
|
|
glfwVideoModeGetSize(mode, &width, &height);
|
|
|
|
|
|
|
|
printf("Name: %s (%s)\n",
|
|
|
|
glfwGetMonitorName(monitor),
|
|
|
|
glfwGetPrimaryMonitor() == monitor ? "primary" : "secondary");
|
|
|
|
printf("Current mode: %s\n", format_mode2(mode));
|
|
|
|
printf("Virtual position: %i, %i\n", x, y);
|
|
|
|
printf("Content scale: %f x %f\n", xscale, yscale);
|
|
|
|
|
|
|
|
printf("Physical size: %i x %i mm (%0.2f dpi at %i x %i)\n",
|
|
|
|
width_mm, height_mm, width * 25.4f / width_mm, width, height);
|
|
|
|
printf("Monitor work area: %i x %i starting at %i, %i\n",
|
|
|
|
workarea_width, workarea_height, workarea_x, workarea_y);
|
|
|
|
|
|
|
|
printf("Modes:\n");
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
printf("%3u: %s", (unsigned int) i, format_mode2(modes[i]));
|
|
|
|
|
|
|
|
if (glfwVideoModesEqual(mode, modes[i]))
|
|
|
|
printf(" (current mode)");
|
|
|
|
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-05 20:13:28 +00:00
|
|
|
static void test_modes(GLFWmonitor* monitor)
|
2012-03-08 00:01:42 +00:00
|
|
|
{
|
2012-08-10 11:03:11 +00:00
|
|
|
int i, count;
|
2013-03-01 12:45:12 +00:00
|
|
|
GLFWwindow* window;
|
2023-03-03 12:20:35 +00:00
|
|
|
const GLFWvideoMode* const* modes = glfwGetVideoModes2(monitor, &count);
|
2012-03-08 00:01:42 +00:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2023-03-03 12:20:35 +00:00
|
|
|
const GLFWvideoMode* mode = modes[i];
|
|
|
|
int width, height, currentWidth, currentHeight;
|
|
|
|
int red, green, blue, currentRed, currentGreen, currentBlue;
|
|
|
|
double refreshRate, currentRefreshRate;
|
|
|
|
|
|
|
|
glfwVideoModeGetSize(mode, &width, &height);
|
|
|
|
glfwVideoModeGetColorDepth(mode, &red, &green, &blue);
|
|
|
|
refreshRate = glfwVideoModeGetRefreshRate(mode);
|
|
|
|
|
|
|
|
glfwWindowHint(GLFW_RED_BITS, red);
|
|
|
|
glfwWindowHint(GLFW_GREEN_BITS, green);
|
|
|
|
glfwWindowHint(GLFW_BLUE_BITS, blue);
|
|
|
|
glfwWindowHintDouble(GLFW_REFRESH_RATE, refreshRate);
|
2012-03-08 00:01:42 +00:00
|
|
|
|
2012-07-10 22:33:32 +00:00
|
|
|
printf("Testing mode %u on monitor %s: %s\n",
|
2012-07-05 14:15:01 +00:00
|
|
|
(unsigned int) i,
|
2012-10-18 21:01:41 +00:00
|
|
|
glfwGetMonitorName(monitor),
|
2023-03-03 12:20:35 +00:00
|
|
|
format_mode2(mode));
|
2012-03-08 00:01:42 +00:00
|
|
|
|
2023-03-03 12:20:35 +00:00
|
|
|
window = glfwCreateWindow(width, height,
|
2013-03-01 12:45:12 +00:00
|
|
|
"Video Mode Test",
|
2023-03-03 12:20:35 +00:00
|
|
|
monitor,
|
2013-03-01 12:45:12 +00:00
|
|
|
NULL);
|
|
|
|
if (!window)
|
2012-03-08 00:01:42 +00:00
|
|
|
{
|
2012-05-06 23:30:55 +00:00
|
|
|
printf("Failed to enter mode %u: %s\n",
|
|
|
|
(unsigned int) i,
|
2023-03-03 12:20:35 +00:00
|
|
|
format_mode2(mode));
|
2012-03-08 00:01:42 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-06-03 10:51:57 +00:00
|
|
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
2013-03-01 12:45:12 +00:00
|
|
|
glfwSetKeyCallback(window, key_callback);
|
2012-10-28 12:45:11 +00:00
|
|
|
|
2013-03-01 12:45:12 +00:00
|
|
|
glfwMakeContextCurrent(window);
|
2019-04-14 15:34:38 +00:00
|
|
|
gladLoadGL(glfwGetProcAddress);
|
2012-03-08 00:01:42 +00:00
|
|
|
glfwSwapInterval(1);
|
|
|
|
|
2012-08-10 13:29:45 +00:00
|
|
|
glfwSetTime(0.0);
|
|
|
|
|
2012-03-08 00:01:42 +00:00
|
|
|
while (glfwGetTime() < 5.0)
|
|
|
|
{
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2013-03-01 12:45:12 +00:00
|
|
|
glfwSwapBuffers(window);
|
2012-03-08 00:01:42 +00:00
|
|
|
glfwPollEvents();
|
|
|
|
|
2013-03-01 12:45:12 +00:00
|
|
|
if (glfwWindowShouldClose(window))
|
2012-03-08 00:01:42 +00:00
|
|
|
{
|
|
|
|
printf("User terminated program\n");
|
2012-10-22 01:20:16 +00:00
|
|
|
|
|
|
|
glfwTerminate();
|
2012-03-08 00:01:42 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-03 12:20:35 +00:00
|
|
|
glGetIntegerv(GL_RED_BITS, ¤tRed);
|
|
|
|
glGetIntegerv(GL_GREEN_BITS, ¤tGreen);
|
|
|
|
glGetIntegerv(GL_BLUE_BITS, ¤tBlue);
|
2012-08-10 11:03:11 +00:00
|
|
|
|
2023-03-03 12:20:35 +00:00
|
|
|
glfwGetWindowSize(window, ¤tWidth, ¤tHeight);
|
2012-08-10 11:03:11 +00:00
|
|
|
|
2023-03-03 12:20:35 +00:00
|
|
|
if (currentRed != red ||
|
|
|
|
currentGreen != green ||
|
|
|
|
currentBlue != blue)
|
2012-03-08 00:01:42 +00:00
|
|
|
{
|
|
|
|
printf("*** Color bit mismatch: (%i %i %i) instead of (%i %i %i)\n",
|
2023-03-03 12:20:35 +00:00
|
|
|
currentRed, currentGreen, currentBlue,
|
|
|
|
red, green, blue);
|
2012-03-08 00:01:42 +00:00
|
|
|
}
|
|
|
|
|
2023-03-03 12:20:35 +00:00
|
|
|
if (currentWidth != width || currentHeight != height)
|
2012-03-08 00:01:42 +00:00
|
|
|
{
|
|
|
|
printf("*** Size mismatch: %ix%i instead of %ix%i\n",
|
2023-03-03 12:20:35 +00:00
|
|
|
currentWidth, currentHeight,
|
|
|
|
width, height);
|
2012-03-08 00:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("Closing window\n");
|
|
|
|
|
2013-03-01 12:45:12 +00:00
|
|
|
glfwDestroyWindow(window);
|
|
|
|
window = NULL;
|
|
|
|
|
2012-03-08 00:01:42 +00:00
|
|
|
glfwPollEvents();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2012-09-12 17:35:52 +00:00
|
|
|
int ch, i, count, mode = LIST_MODE;
|
2013-01-05 20:13:28 +00:00
|
|
|
GLFWmonitor** monitors;
|
2012-03-08 00:01:42 +00:00
|
|
|
|
2023-03-03 12:20:35 +00:00
|
|
|
while ((ch = getopt(argc, argv, "tho")) != -1)
|
2012-03-08 00:01:42 +00:00
|
|
|
{
|
|
|
|
switch (ch)
|
|
|
|
{
|
|
|
|
case 'h':
|
|
|
|
usage();
|
|
|
|
exit(EXIT_SUCCESS);
|
2023-03-03 12:20:35 +00:00
|
|
|
case 'o':
|
|
|
|
mode = LIST_MODE_OLD;
|
|
|
|
break;
|
2012-03-08 00:01:42 +00:00
|
|
|
case 't':
|
|
|
|
mode = TEST_MODE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
glfwSetErrorCallback(error_callback);
|
|
|
|
|
2020-03-05 19:32:19 +00:00
|
|
|
glfwInitHint(GLFW_COCOA_MENUBAR, GLFW_FALSE);
|
|
|
|
|
2012-03-08 00:01:42 +00:00
|
|
|
if (!glfwInit())
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
2012-09-12 17:35:52 +00:00
|
|
|
monitors = glfwGetMonitors(&count);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
2012-07-05 14:15:01 +00:00
|
|
|
{
|
|
|
|
if (mode == LIST_MODE)
|
2023-03-03 12:20:35 +00:00
|
|
|
list_modes2(monitors[i]);
|
|
|
|
else if (mode == LIST_MODE_OLD)
|
2012-09-12 17:35:52 +00:00
|
|
|
list_modes(monitors[i]);
|
2012-07-05 14:15:01 +00:00
|
|
|
else if (mode == TEST_MODE)
|
2012-09-12 17:35:52 +00:00
|
|
|
test_modes(monitors[i]);
|
2012-07-05 14:15:01 +00:00
|
|
|
}
|
2012-03-08 00:01:42 +00:00
|
|
|
|
2012-10-22 01:20:16 +00:00
|
|
|
glfwTerminate();
|
2012-03-08 00:01:42 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|