mirror of
				https://github.com/glfw/glfw.git
				synced 2025-10-31 04:32:26 +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)
 | // Fullscren management (fullscreen.c)
 | ||||||
|  | const GLFWvidmode* _glfwChooseVideoMode(const GLFWvidmode* desired, | ||||||
|  |                                         const GLFWvidmode* alternatives, | ||||||
|  |                                         unsigned int count); | ||||||
| int _glfwCompareVideoModes(const GLFWvidmode* first, const GLFWvidmode* second); | int _glfwCompareVideoModes(const GLFWvidmode* first, const GLFWvidmode* second); | ||||||
| void _glfwSplitBPP(int bpp, int* red, int* green, int* blue); | void _glfwSplitBPP(int bpp, int* red, int* green, int* blue); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -32,6 +32,8 @@ | |||||||
| 
 | 
 | ||||||
| #include <string.h> | #include <string.h> | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
|  | #include <limits.h> | ||||||
|  | 
 | ||||||
| #if defined(_MSC_VER) | #if defined(_MSC_VER) | ||||||
|  #include <malloc.h> |  #include <malloc.h> | ||||||
|  #define strdup _strdup |  #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
 | // Lexical comparison of GLFW video modes
 | ||||||
| //========================================================================
 | //========================================================================
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user