Simplified mode printing.

This commit is contained in:
Camilla Berglund 2012-05-07 01:30:55 +02:00
parent 5527e52f58
commit 6059523b6d

View File

@ -49,12 +49,18 @@ static void usage(void)
printf(" modes -h\n"); printf(" modes -h\n");
} }
static void print_mode(GLFWvidmode* mode) static const char* format_mode(GLFWvidmode* mode)
{ {
printf("%i x %i x %i (%i %i %i)", static char buffer[512];
snprintf(buffer, sizeof(buffer),
"%i x %i x %i (%i %i %i)",
mode->width, mode->height, mode->width, mode->height,
mode->redBits + mode->greenBits + mode->blueBits, mode->redBits + mode->greenBits + mode->blueBits,
mode->redBits, mode->greenBits, mode->blueBits); mode->redBits, mode->greenBits, mode->blueBits);
buffer[sizeof(buffer) - 1] = '\0';
return buffer;
} }
static void error_callback(int error, const char* description) static void error_callback(int error, const char* description)
@ -109,16 +115,13 @@ static void list_modes(void)
GLFWvidmode* modes = get_video_modes(&count); GLFWvidmode* modes = get_video_modes(&count);
glfwGetDesktopMode(&desktop_mode); glfwGetDesktopMode(&desktop_mode);
printf("Desktop mode: "); printf("Desktop mode: %s\n", format_mode(&desktop_mode));
print_mode(&desktop_mode);
putchar('\n');
printf("Available modes:\n"); printf("Available modes:\n");
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
printf("%3u: ", (unsigned int) i); printf("%3u: %s", (unsigned int) i, format_mode(modes + i));
print_mode(modes + i);
if (memcmp(&desktop_mode, modes + i, sizeof(GLFWvidmode)) == 0) if (memcmp(&desktop_mode, modes + i, sizeof(GLFWvidmode)) == 0)
printf(" (desktop mode)"); printf(" (desktop mode)");
@ -147,18 +150,16 @@ static void test_modes(void)
glfwOpenWindowHint(GLFW_GREEN_BITS, mode->greenBits); glfwOpenWindowHint(GLFW_GREEN_BITS, mode->greenBits);
glfwOpenWindowHint(GLFW_BLUE_BITS, mode->blueBits); glfwOpenWindowHint(GLFW_BLUE_BITS, mode->blueBits);
printf("Opening "); printf("Testing mode %u: %s", (unsigned int) i, format_mode(mode));
print_mode(mode);
printf(" window\n");
window = glfwOpenWindow(mode->width, mode->height, window = glfwOpenWindow(mode->width, mode->height,
GLFW_FULLSCREEN, "Video Mode Test", GLFW_FULLSCREEN, "Video Mode Test",
NULL); NULL);
if (!window) if (!window)
{ {
printf("Failed to enter mode %u: ", (unsigned int) i); printf("Failed to enter mode %u: %s\n",
print_mode(mode); (unsigned int) i,
putchar('\n'); format_mode(mode));
continue; continue;
} }