2012-03-07 19:01:42 -05:00
|
|
|
//========================================================================
|
|
|
|
// Video mode test
|
|
|
|
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
//
|
|
|
|
// This test enumerates or verifies video modes
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
#include <GL/glfw3.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2012-05-06 19:13:07 -04:00
|
|
|
#include <string.h>
|
2012-03-07 19:01:42 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "getopt.h"
|
|
|
|
|
2012-09-13 11:29:07 -04:00
|
|
|
static GLFWwindow window_handle = NULL;
|
2012-03-07 19:01:42 -05:00
|
|
|
|
|
|
|
enum Mode
|
|
|
|
{
|
|
|
|
LIST_MODE,
|
|
|
|
TEST_MODE
|
|
|
|
};
|
|
|
|
|
|
|
|
static void usage(void)
|
|
|
|
{
|
2012-05-06 18:29:36 -04:00
|
|
|
printf("Usage: modes [-t]\n");
|
2012-03-07 19:01:42 -05:00
|
|
|
printf(" modes -h\n");
|
|
|
|
}
|
|
|
|
|
2012-12-02 15:18:01 -05:00
|
|
|
static const char* format_mode(const GLFWvidmode* mode)
|
2012-03-07 19:01:42 -05:00
|
|
|
{
|
2012-05-06 19:30:55 -04:00
|
|
|
static char buffer[512];
|
|
|
|
|
2012-08-12 06:29:55 -04:00
|
|
|
sprintf(buffer,
|
|
|
|
"%i x %i x %i (%i %i %i)",
|
|
|
|
mode->width, mode->height,
|
|
|
|
mode->redBits + mode->greenBits + mode->blueBits,
|
|
|
|
mode->redBits, mode->greenBits, mode->blueBits);
|
2012-05-06 19:30:55 -04:00
|
|
|
|
|
|
|
buffer[sizeof(buffer) - 1] = '\0';
|
|
|
|
return buffer;
|
2012-03-07 19:01:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void error_callback(int error, const char* description)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Error: %s\n", description);
|
|
|
|
}
|
|
|
|
|
2012-09-13 11:29:07 -04:00
|
|
|
static void window_size_callback(GLFWwindow window, int width, int height)
|
2012-03-07 19:01:42 -05:00
|
|
|
{
|
|
|
|
printf("Window resized to %ix%i\n", width, height);
|
|
|
|
|
|
|
|
glViewport(0, 0, width, height);
|
|
|
|
}
|
|
|
|
|
2012-09-13 11:29:07 -04:00
|
|
|
static int window_close_callback(GLFWwindow window)
|
2012-03-07 19:01:42 -05:00
|
|
|
{
|
2012-09-13 11:29:07 -04:00
|
|
|
window_handle = NULL;
|
2012-03-07 19:01:42 -05:00
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2012-09-13 11:29:07 -04:00
|
|
|
static void key_callback(GLFWwindow window, int key, int action)
|
2012-05-06 18:44:39 -04:00
|
|
|
{
|
|
|
|
if (key == GLFW_KEY_ESCAPE)
|
|
|
|
{
|
2012-08-06 11:56:41 -04:00
|
|
|
glfwDestroyWindow(window);
|
2012-09-13 11:29:07 -04:00
|
|
|
window_handle = NULL;
|
2012-05-06 18:44:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-05 10:15:01 -04:00
|
|
|
static void list_modes(GLFWmonitor monitor)
|
2012-05-06 19:12:08 -04:00
|
|
|
{
|
2012-10-18 17:09:28 -04:00
|
|
|
int count, widthMM, heightMM, dpi, i;
|
2012-08-29 19:53:23 -04:00
|
|
|
GLFWvidmode mode;
|
2012-12-02 15:18:01 -05:00
|
|
|
const GLFWvidmode* modes = glfwGetVideoModes(monitor, &count);
|
2012-05-06 19:12:08 -04:00
|
|
|
|
2012-08-29 19:53:23 -04:00
|
|
|
glfwGetVideoMode(monitor, &mode);
|
2012-03-07 19:01:42 -05:00
|
|
|
|
2012-10-18 17:01:41 -04:00
|
|
|
printf("Name: %s\n", glfwGetMonitorName(monitor));
|
2012-08-29 20:12:02 -04:00
|
|
|
printf("Current mode: %s\n", format_mode(&mode));
|
2012-09-13 10:47:59 -04:00
|
|
|
printf("Virtual position: %i %i\n",
|
2012-10-21 20:39:22 -04:00
|
|
|
glfwGetMonitorParam(monitor, GLFW_MONITOR_POS_X),
|
|
|
|
glfwGetMonitorParam(monitor, GLFW_MONITOR_POS_Y));
|
2012-10-18 17:09:28 -04:00
|
|
|
|
2012-12-12 19:56:33 -05:00
|
|
|
widthMM = glfwGetMonitorParam(monitor, GLFW_MONITOR_WIDTH_MM);
|
|
|
|
heightMM = glfwGetMonitorParam(monitor, GLFW_MONITOR_HEIGHT_MM);
|
2012-10-18 17:09:28 -04:00
|
|
|
dpi = (int) ((float) mode.width * 25.4f / (float) widthMM);
|
|
|
|
printf("Physical size: %i x %i mm (%i dpi)\n", widthMM, heightMM, dpi);
|
2012-05-06 18:32:03 -04:00
|
|
|
|
2012-08-29 20:12:02 -04:00
|
|
|
printf("Modes:\n");
|
|
|
|
|
2012-03-07 19:01:42 -05:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2012-05-06 19:30:55 -04:00
|
|
|
printf("%3u: %s", (unsigned int) i, format_mode(modes + i));
|
2012-05-06 19:13:07 -04:00
|
|
|
|
2012-08-29 19:53:23 -04:00
|
|
|
if (memcmp(&mode, modes + i, sizeof(GLFWvidmode)) == 0)
|
|
|
|
printf(" (current mode)");
|
2012-05-06 19:13:07 -04:00
|
|
|
|
2012-03-07 19:01:42 -05:00
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-05 10:15:01 -04:00
|
|
|
static void test_modes(GLFWmonitor monitor)
|
2012-03-07 19:01:42 -05:00
|
|
|
{
|
2012-08-10 07:03:11 -04:00
|
|
|
int i, count;
|
2012-12-02 15:18:01 -05:00
|
|
|
const GLFWvidmode* modes = glfwGetVideoModes(monitor, &count);
|
2012-03-07 19:01:42 -05:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2012-12-02 15:18:01 -05:00
|
|
|
const GLFWvidmode* mode = modes + i;
|
2012-08-10 07:03:11 -04:00
|
|
|
GLFWvidmode current;
|
2012-05-06 18:33:21 -04:00
|
|
|
|
2012-08-06 11:56:41 -04:00
|
|
|
glfwWindowHint(GLFW_RED_BITS, mode->redBits);
|
|
|
|
glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
|
|
|
|
glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
|
2012-03-07 19:01:42 -05:00
|
|
|
|
2012-07-10 18:33:32 -04:00
|
|
|
printf("Testing mode %u on monitor %s: %s\n",
|
2012-07-05 10:15:01 -04:00
|
|
|
(unsigned int) i,
|
2012-10-18 17:01:41 -04:00
|
|
|
glfwGetMonitorName(monitor),
|
2012-07-05 10:15:01 -04:00
|
|
|
format_mode(mode));
|
2012-03-07 19:01:42 -05:00
|
|
|
|
2012-09-13 11:29:07 -04:00
|
|
|
window_handle = glfwCreateWindow(mode->width, mode->height,
|
2012-09-27 15:37:36 -04:00
|
|
|
"Video Mode Test",
|
|
|
|
glfwGetPrimaryMonitor(),
|
2012-09-13 11:29:07 -04:00
|
|
|
NULL);
|
|
|
|
if (!window_handle)
|
2012-03-07 19:01:42 -05:00
|
|
|
{
|
2012-05-06 19:30:55 -04:00
|
|
|
printf("Failed to enter mode %u: %s\n",
|
|
|
|
(unsigned int) i,
|
|
|
|
format_mode(mode));
|
2012-03-07 19:01:42 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-10-28 08:45:11 -04:00
|
|
|
glfwSetWindowSizeCallback(window_handle, window_size_callback);
|
|
|
|
glfwSetWindowCloseCallback(window_handle, window_close_callback);
|
|
|
|
glfwSetKeyCallback(window_handle, key_callback);
|
|
|
|
|
2012-09-13 11:29:07 -04:00
|
|
|
glfwMakeContextCurrent(window_handle);
|
2012-03-07 19:01:42 -05:00
|
|
|
glfwSwapInterval(1);
|
|
|
|
|
2012-08-10 09:29:45 -04:00
|
|
|
glfwSetTime(0.0);
|
|
|
|
|
2012-03-07 19:01:42 -05:00
|
|
|
while (glfwGetTime() < 5.0)
|
|
|
|
{
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2012-09-13 11:29:07 -04:00
|
|
|
glfwSwapBuffers(window_handle);
|
2012-03-07 19:01:42 -05:00
|
|
|
glfwPollEvents();
|
|
|
|
|
2012-09-13 11:29:07 -04:00
|
|
|
if (!window_handle)
|
2012-03-07 19:01:42 -05:00
|
|
|
{
|
|
|
|
printf("User terminated program\n");
|
2012-10-21 21:20:16 -04:00
|
|
|
|
|
|
|
glfwTerminate();
|
2012-03-07 19:01:42 -05:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-10 07:03:11 -04:00
|
|
|
glGetIntegerv(GL_RED_BITS, ¤t.redBits);
|
|
|
|
glGetIntegerv(GL_GREEN_BITS, ¤t.greenBits);
|
|
|
|
glGetIntegerv(GL_BLUE_BITS, ¤t.blueBits);
|
|
|
|
|
2012-09-13 11:29:07 -04:00
|
|
|
glfwGetWindowSize(window_handle, ¤t.width, ¤t.height);
|
2012-08-10 07:03:11 -04:00
|
|
|
|
|
|
|
if (current.redBits != mode->redBits ||
|
|
|
|
current.greenBits != mode->greenBits ||
|
|
|
|
current.blueBits != mode->blueBits)
|
2012-03-07 19:01:42 -05:00
|
|
|
{
|
|
|
|
printf("*** Color bit mismatch: (%i %i %i) instead of (%i %i %i)\n",
|
2012-08-10 07:03:11 -04:00
|
|
|
current.redBits, current.greenBits, current.blueBits,
|
|
|
|
mode->redBits, mode->greenBits, mode->blueBits);
|
2012-03-07 19:01:42 -05:00
|
|
|
}
|
|
|
|
|
2012-08-10 07:03:11 -04:00
|
|
|
if (current.width != mode->width || current.height != mode->height)
|
2012-03-07 19:01:42 -05:00
|
|
|
{
|
|
|
|
printf("*** Size mismatch: %ix%i instead of %ix%i\n",
|
2012-08-10 07:03:11 -04:00
|
|
|
current.width, current.height,
|
2012-05-06 18:33:21 -04:00
|
|
|
mode->width, mode->height);
|
2012-03-07 19:01:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("Closing window\n");
|
|
|
|
|
2012-09-13 11:29:07 -04:00
|
|
|
glfwDestroyWindow(window_handle);
|
|
|
|
window_handle = NULL;
|
2012-03-07 19:01:42 -05:00
|
|
|
glfwPollEvents();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2012-09-12 13:35:52 -04:00
|
|
|
int ch, i, count, mode = LIST_MODE;
|
2012-12-02 15:18:01 -05:00
|
|
|
const GLFWmonitor* monitors;
|
2012-03-07 19:01:42 -05:00
|
|
|
|
2012-05-06 18:29:36 -04:00
|
|
|
while ((ch = getopt(argc, argv, "th")) != -1)
|
2012-03-07 19:01:42 -05:00
|
|
|
{
|
|
|
|
switch (ch)
|
|
|
|
{
|
|
|
|
case 'h':
|
|
|
|
usage();
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
case 't':
|
|
|
|
mode = TEST_MODE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
glfwSetErrorCallback(error_callback);
|
|
|
|
|
|
|
|
if (!glfwInit())
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
2012-09-12 13:35:52 -04:00
|
|
|
monitors = glfwGetMonitors(&count);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
2012-07-05 10:15:01 -04:00
|
|
|
{
|
|
|
|
if (mode == LIST_MODE)
|
2012-09-12 13:35:52 -04:00
|
|
|
list_modes(monitors[i]);
|
2012-07-05 10:15:01 -04:00
|
|
|
else if (mode == TEST_MODE)
|
2012-09-12 13:35:52 -04:00
|
|
|
test_modes(monitors[i]);
|
2012-07-05 10:15:01 -04:00
|
|
|
}
|
2012-03-07 19:01:42 -05:00
|
|
|
|
2012-10-21 21:20:16 -04:00
|
|
|
glfwTerminate();
|
2012-03-07 19:01:42 -05:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|