Restructured modes test for better encapsulation.
This commit is contained in:
parent
eeed6394c0
commit
d109d8a6d2
@ -83,29 +83,52 @@ static void key_callback(GLFWwindow dummy, int key, int action)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void list_modes(GLFWvidmode* modes, int count)
|
static GLFWvidmode* get_video_modes(size_t* found)
|
||||||
{
|
{
|
||||||
int i;
|
size_t count = 0;
|
||||||
GLFWvidmode mode;
|
GLFWvidmode* modes = NULL;
|
||||||
|
|
||||||
glfwGetDesktopMode(&mode);
|
for (;;)
|
||||||
|
{
|
||||||
|
count += 256;
|
||||||
|
modes = realloc(modes, sizeof(GLFWvidmode) * count);
|
||||||
|
|
||||||
|
*found = glfwGetVideoModes(modes, count);
|
||||||
|
if (*found < count)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return modes;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void list_modes(void)
|
||||||
|
{
|
||||||
|
size_t count, i;
|
||||||
|
GLFWvidmode desktop_mode;
|
||||||
|
GLFWvidmode* modes = get_video_modes(&count);
|
||||||
|
|
||||||
|
glfwGetDesktopMode(&desktop_mode);
|
||||||
printf("Desktop mode: ");
|
printf("Desktop mode: ");
|
||||||
print_mode(&mode);
|
print_mode(&desktop_mode);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
|
||||||
printf("Available modes:\n");
|
printf("Available modes:\n");
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
printf("%3i: ", i);
|
printf("%3u: ", (unsigned int) i);
|
||||||
print_mode(modes + i);
|
print_mode(modes + i);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(modes);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_modes(GLFWvidmode* modes, int count)
|
static void test_modes(void)
|
||||||
{
|
{
|
||||||
int i, width, height;
|
int width, height;
|
||||||
|
size_t i, count;
|
||||||
|
GLFWvidmode* modes = get_video_modes(&count);
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
glfwSetWindowCloseCallback(window_close_callback);
|
glfwSetWindowCloseCallback(window_close_callback);
|
||||||
@ -128,7 +151,7 @@ static void test_modes(GLFWvidmode* modes, int count)
|
|||||||
NULL);
|
NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
printf("Failed to enter mode %i: ", i);
|
printf("Failed to enter mode %u: ", (unsigned int) i);
|
||||||
print_mode(mode);
|
print_mode(mode);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
continue;
|
continue;
|
||||||
@ -178,12 +201,13 @@ static void test_modes(GLFWvidmode* modes, int count)
|
|||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
window = NULL;
|
window = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(modes);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int ch, found, count = 0, mode = LIST_MODE;
|
int ch, mode = LIST_MODE;
|
||||||
GLFWvidmode* modes = NULL;
|
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "th")) != -1)
|
while ((ch = getopt(argc, argv, "th")) != -1)
|
||||||
{
|
{
|
||||||
@ -209,23 +233,10 @@ int main(int argc, char** argv)
|
|||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
count += 256;
|
|
||||||
modes = realloc(modes, sizeof(GLFWvidmode) * count);
|
|
||||||
|
|
||||||
found = glfwGetVideoModes(modes, count);
|
|
||||||
if (found < count)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode == LIST_MODE)
|
if (mode == LIST_MODE)
|
||||||
list_modes(modes, found);
|
list_modes();
|
||||||
else if (mode == TEST_MODE)
|
else if (mode == TEST_MODE)
|
||||||
test_modes(modes, found);
|
test_modes();
|
||||||
|
|
||||||
free(modes);
|
|
||||||
modes = NULL;
|
|
||||||
|
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user