mirror of
https://github.com/glfw/glfw.git
synced 2024-11-10 00:51:47 +00:00
Added generic video mode selection.
This commit is contained in:
parent
52dac79219
commit
cf42282cfb
@ -378,6 +378,9 @@ void _glfwInputMonitorChange(void);
|
||||
//========================================================================
|
||||
|
||||
// Fullscren management (fullscreen.c)
|
||||
const GLFWvidmode* _glfwChooseVideoMode(const GLFWvidmode* desired,
|
||||
const GLFWvidmode* alternatives,
|
||||
unsigned int count);
|
||||
int _glfwCompareVideoModes(const GLFWvidmode* first, const GLFWvidmode* second);
|
||||
void _glfwSplitBPP(int bpp, int* red, int* green, int* blue);
|
||||
|
||||
|
@ -32,6 +32,8 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#include <malloc.h>
|
||||
#define strdup _strdup
|
||||
@ -195,6 +197,45 @@ void _glfwDestroyMonitors(void)
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Returns the video mode closest to the desired one
|
||||
//========================================================================
|
||||
|
||||
const GLFWvidmode* _glfwChooseVideoMode(const GLFWvidmode* desired,
|
||||
const GLFWvidmode* alternatives,
|
||||
unsigned int count)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int sizeDiff, leastSizeDiff = UINT_MAX;
|
||||
unsigned int colorDiff, leastColorDiff = UINT_MAX;
|
||||
const GLFWvidmode* current;
|
||||
const GLFWvidmode* closest = NULL;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
current = alternatives + i;
|
||||
|
||||
colorDiff = abs((current->redBits + current->greenBits + current->blueBits) -
|
||||
(desired->redBits + desired->greenBits + desired->blueBits));
|
||||
|
||||
sizeDiff = abs((current->width - desired->width) *
|
||||
(current->width - desired->width) +
|
||||
(current->height - desired->height) *
|
||||
(current->height - desired->height));
|
||||
|
||||
if ((colorDiff < leastColorDiff) ||
|
||||
(colorDiff == leastColorDiff && sizeDiff < leastSizeDiff))
|
||||
{
|
||||
closest = current;
|
||||
leastSizeDiff = sizeDiff;
|
||||
leastColorDiff = colorDiff;
|
||||
}
|
||||
}
|
||||
|
||||
return closest;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Lexical comparison of GLFW video modes
|
||||
//========================================================================
|
||||
|
Loading…
Reference in New Issue
Block a user