diff --git a/readme.html b/readme.html
index bde16bcf4..33832689c 100644
--- a/readme.html
+++ b/readme.html
@@ -280,6 +280,7 @@ version of GLFW.
Added windows simple multi-window test program
Added sharing simple OpenGL object sharing test program
Added dynamic simple dynamic linking test program
+ Added modes video mode enumeration and setting test program
Added a parameter to glfwOpenWindow for specifying a context the new window's context will share objects with
Added initial window title parameter to glfwOpenWindow
Added glfwSetGamma, glfwSetGammaRamp and glfwGetGammaRamp functions and GLFWgammaramp type for monitor gamma ramp control
diff --git a/src/cocoa_fullscreen.m b/src/cocoa_fullscreen.m
index d3a715ba5..147913fbe 100644
--- a/src/cocoa_fullscreen.m
+++ b/src/cocoa_fullscreen.m
@@ -64,6 +64,7 @@ static GLboolean modeIsGood(CGDisplayModeRef mode)
return GL_TRUE;
}
+
//========================================================================
// Convert Core Graphics display mode to GLFW video mode
//========================================================================
@@ -217,6 +218,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
return stored;
}
+
//========================================================================
// Get the desktop video mode
//========================================================================
diff --git a/src/cocoa_init.m b/src/cocoa_init.m
index 008987781..16bd98eb9 100644
--- a/src/cocoa_init.m
+++ b/src/cocoa_init.m
@@ -33,6 +33,7 @@
//========================================================================
// Change to our application bundle's resources directory, if present
//========================================================================
+
static void changeToResourcesDirectory(void)
{
char resourcesPath[MAXPATHLEN];
@@ -112,6 +113,7 @@ int _glfwPlatformInit(void)
return GL_TRUE;
}
+
//========================================================================
// Close window, if open, and shut down GLFW
//========================================================================
diff --git a/src/cocoa_joystick.m b/src/cocoa_joystick.m
index a167692f5..45b3be0fa 100644
--- a/src/cocoa_joystick.m
+++ b/src/cocoa_joystick.m
@@ -579,4 +579,3 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
return numbuttons;
}
-
diff --git a/src/cocoa_opengl.m b/src/cocoa_opengl.m
index bd3827fcb..0ea39076b 100644
--- a/src/cocoa_opengl.m
+++ b/src/cocoa_opengl.m
@@ -59,6 +59,7 @@ void _glfwPlatformSwapBuffers(void)
[window->NSGL.context flushBuffer];
}
+
//========================================================================
// Set double buffering swap interval
//========================================================================
@@ -71,6 +72,7 @@ void _glfwPlatformSwapInterval(int interval)
[window->NSGL.context setValues:&sync forParameter:NSOpenGLCPSwapInterval];
}
+
//========================================================================
// Check if an OpenGL extension is available at runtime
//========================================================================
@@ -81,6 +83,7 @@ int _glfwPlatformExtensionSupported(const char* extension)
return GL_FALSE;
}
+
//========================================================================
// Get the function pointer to an OpenGL function
//========================================================================
@@ -99,6 +102,7 @@ void* _glfwPlatformGetProcAddress(const char* procname)
return symbol;
}
+
//========================================================================
// Copies the specified OpenGL state categories from src to dst
//========================================================================
diff --git a/src/cocoa_time.c b/src/cocoa_time.c
index 4facbffb9..745b42396 100644
--- a/src/cocoa_time.c
+++ b/src/cocoa_time.c
@@ -74,6 +74,7 @@ double _glfwPlatformGetTime(void)
_glfwLibrary.NS.timer.resolution;
}
+
//========================================================================
// Set timer value in seconds
//========================================================================
diff --git a/src/cocoa_window.m b/src/cocoa_window.m
index 9d5ee5ece..dd5483617 100644
--- a/src/cocoa_window.m
+++ b/src/cocoa_window.m
@@ -112,6 +112,7 @@
@end
+
//========================================================================
// Delegate for application related notifications
//========================================================================
@@ -133,142 +134,6 @@
@end
-//========================================================================
-// Keyboard symbol translation table
-//========================================================================
-
-// TODO: Need to find mappings for F13-F15, volume down/up/mute, and eject.
-static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] =
-{
- /* 00 */ GLFW_KEY_A,
- /* 01 */ GLFW_KEY_S,
- /* 02 */ GLFW_KEY_D,
- /* 03 */ GLFW_KEY_F,
- /* 04 */ GLFW_KEY_H,
- /* 05 */ GLFW_KEY_G,
- /* 06 */ GLFW_KEY_Z,
- /* 07 */ GLFW_KEY_X,
- /* 08 */ GLFW_KEY_C,
- /* 09 */ GLFW_KEY_V,
- /* 0a */ GLFW_KEY_GRAVE_ACCENT,
- /* 0b */ GLFW_KEY_B,
- /* 0c */ GLFW_KEY_Q,
- /* 0d */ GLFW_KEY_W,
- /* 0e */ GLFW_KEY_E,
- /* 0f */ GLFW_KEY_R,
- /* 10 */ GLFW_KEY_Y,
- /* 11 */ GLFW_KEY_T,
- /* 12 */ GLFW_KEY_1,
- /* 13 */ GLFW_KEY_2,
- /* 14 */ GLFW_KEY_3,
- /* 15 */ GLFW_KEY_4,
- /* 16 */ GLFW_KEY_6,
- /* 17 */ GLFW_KEY_5,
- /* 18 */ GLFW_KEY_EQUAL,
- /* 19 */ GLFW_KEY_9,
- /* 1a */ GLFW_KEY_7,
- /* 1b */ GLFW_KEY_MINUS,
- /* 1c */ GLFW_KEY_8,
- /* 1d */ GLFW_KEY_0,
- /* 1e */ GLFW_KEY_RIGHT_BRACKET,
- /* 1f */ GLFW_KEY_O,
- /* 20 */ GLFW_KEY_U,
- /* 21 */ GLFW_KEY_LEFT_BRACKET,
- /* 22 */ GLFW_KEY_I,
- /* 23 */ GLFW_KEY_P,
- /* 24 */ GLFW_KEY_ENTER,
- /* 25 */ GLFW_KEY_L,
- /* 26 */ GLFW_KEY_J,
- /* 27 */ GLFW_KEY_APOSTROPHE,
- /* 28 */ GLFW_KEY_K,
- /* 29 */ GLFW_KEY_SEMICOLON,
- /* 2a */ GLFW_KEY_BACKSLASH,
- /* 2b */ GLFW_KEY_COMMA,
- /* 2c */ GLFW_KEY_SLASH,
- /* 2d */ GLFW_KEY_N,
- /* 2e */ GLFW_KEY_M,
- /* 2f */ GLFW_KEY_PERIOD,
- /* 30 */ GLFW_KEY_TAB,
- /* 31 */ GLFW_KEY_SPACE,
- /* 32 */ GLFW_KEY_WORLD_1,
- /* 33 */ GLFW_KEY_BACKSPACE,
- /* 34 */ -1,
- /* 35 */ GLFW_KEY_ESCAPE,
- /* 36 */ GLFW_KEY_RIGHT_SUPER,
- /* 37 */ GLFW_KEY_LEFT_SUPER,
- /* 38 */ GLFW_KEY_LEFT_SHIFT,
- /* 39 */ GLFW_KEY_CAPS_LOCK,
- /* 3a */ GLFW_KEY_LEFT_ALT,
- /* 3b */ GLFW_KEY_LEFT_CONTROL,
- /* 3c */ GLFW_KEY_RIGHT_SHIFT,
- /* 3d */ GLFW_KEY_RIGHT_ALT,
- /* 3e */ GLFW_KEY_RIGHT_CONTROL,
- /* 3f */ -1, /* Function */
- /* 40 */ GLFW_KEY_F17,
- /* 41 */ GLFW_KEY_KP_DECIMAL,
- /* 42 */ -1,
- /* 43 */ GLFW_KEY_KP_MULTIPLY,
- /* 44 */ -1,
- /* 45 */ GLFW_KEY_KP_ADD,
- /* 46 */ -1,
- /* 47 */ GLFW_KEY_NUM_LOCK, /* Really KeypadClear... */
- /* 48 */ -1, /* VolumeUp */
- /* 49 */ -1, /* VolumeDown */
- /* 4a */ -1, /* Mute */
- /* 4b */ GLFW_KEY_KP_DIVIDE,
- /* 4c */ GLFW_KEY_KP_ENTER,
- /* 4d */ -1,
- /* 4e */ GLFW_KEY_KP_SUBTRACT,
- /* 4f */ GLFW_KEY_F18,
- /* 50 */ GLFW_KEY_F19,
- /* 51 */ GLFW_KEY_KP_EQUAL,
- /* 52 */ GLFW_KEY_KP_0,
- /* 53 */ GLFW_KEY_KP_1,
- /* 54 */ GLFW_KEY_KP_2,
- /* 55 */ GLFW_KEY_KP_3,
- /* 56 */ GLFW_KEY_KP_4,
- /* 57 */ GLFW_KEY_KP_5,
- /* 58 */ GLFW_KEY_KP_6,
- /* 59 */ GLFW_KEY_KP_7,
- /* 5a */ GLFW_KEY_F20,
- /* 5b */ GLFW_KEY_KP_8,
- /* 5c */ GLFW_KEY_KP_9,
- /* 5d */ -1,
- /* 5e */ -1,
- /* 5f */ -1,
- /* 60 */ GLFW_KEY_F5,
- /* 61 */ GLFW_KEY_F6,
- /* 62 */ GLFW_KEY_F7,
- /* 63 */ GLFW_KEY_F3,
- /* 64 */ GLFW_KEY_F8,
- /* 65 */ GLFW_KEY_F9,
- /* 66 */ -1,
- /* 67 */ GLFW_KEY_F11,
- /* 68 */ -1,
- /* 69 */ GLFW_KEY_F13,
- /* 6a */ GLFW_KEY_F16,
- /* 6b */ GLFW_KEY_F14,
- /* 6c */ -1,
- /* 6d */ GLFW_KEY_F10,
- /* 6e */ -1,
- /* 6f */ GLFW_KEY_F12,
- /* 70 */ -1,
- /* 71 */ GLFW_KEY_F15,
- /* 72 */ GLFW_KEY_INSERT, /* Really Help... */
- /* 73 */ GLFW_KEY_HOME,
- /* 74 */ GLFW_KEY_PAGE_UP,
- /* 75 */ GLFW_KEY_DELETE,
- /* 76 */ GLFW_KEY_F4,
- /* 77 */ GLFW_KEY_END,
- /* 78 */ GLFW_KEY_F2,
- /* 79 */ GLFW_KEY_PAGE_DOWN,
- /* 7a */ GLFW_KEY_F1,
- /* 7b */ GLFW_KEY_LEFT,
- /* 7c */ GLFW_KEY_RIGHT,
- /* 7d */ GLFW_KEY_DOWN,
- /* 7e */ GLFW_KEY_UP,
- /* 7f */ -1,
-};
//========================================================================
// Converts a Mac OS X keycode to a GLFW keycode
@@ -276,15 +141,150 @@ static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] =
static int convertMacKeyCode(unsigned int macKeyCode)
{
+ // Keyboard symbol translation table
+ // TODO: Need to find mappings for F13-F15, volume down/up/mute, and eject.
+ static const unsigned int table[128] =
+ {
+ /* 00 */ GLFW_KEY_A,
+ /* 01 */ GLFW_KEY_S,
+ /* 02 */ GLFW_KEY_D,
+ /* 03 */ GLFW_KEY_F,
+ /* 04 */ GLFW_KEY_H,
+ /* 05 */ GLFW_KEY_G,
+ /* 06 */ GLFW_KEY_Z,
+ /* 07 */ GLFW_KEY_X,
+ /* 08 */ GLFW_KEY_C,
+ /* 09 */ GLFW_KEY_V,
+ /* 0a */ GLFW_KEY_GRAVE_ACCENT,
+ /* 0b */ GLFW_KEY_B,
+ /* 0c */ GLFW_KEY_Q,
+ /* 0d */ GLFW_KEY_W,
+ /* 0e */ GLFW_KEY_E,
+ /* 0f */ GLFW_KEY_R,
+ /* 10 */ GLFW_KEY_Y,
+ /* 11 */ GLFW_KEY_T,
+ /* 12 */ GLFW_KEY_1,
+ /* 13 */ GLFW_KEY_2,
+ /* 14 */ GLFW_KEY_3,
+ /* 15 */ GLFW_KEY_4,
+ /* 16 */ GLFW_KEY_6,
+ /* 17 */ GLFW_KEY_5,
+ /* 18 */ GLFW_KEY_EQUAL,
+ /* 19 */ GLFW_KEY_9,
+ /* 1a */ GLFW_KEY_7,
+ /* 1b */ GLFW_KEY_MINUS,
+ /* 1c */ GLFW_KEY_8,
+ /* 1d */ GLFW_KEY_0,
+ /* 1e */ GLFW_KEY_RIGHT_BRACKET,
+ /* 1f */ GLFW_KEY_O,
+ /* 20 */ GLFW_KEY_U,
+ /* 21 */ GLFW_KEY_LEFT_BRACKET,
+ /* 22 */ GLFW_KEY_I,
+ /* 23 */ GLFW_KEY_P,
+ /* 24 */ GLFW_KEY_ENTER,
+ /* 25 */ GLFW_KEY_L,
+ /* 26 */ GLFW_KEY_J,
+ /* 27 */ GLFW_KEY_APOSTROPHE,
+ /* 28 */ GLFW_KEY_K,
+ /* 29 */ GLFW_KEY_SEMICOLON,
+ /* 2a */ GLFW_KEY_BACKSLASH,
+ /* 2b */ GLFW_KEY_COMMA,
+ /* 2c */ GLFW_KEY_SLASH,
+ /* 2d */ GLFW_KEY_N,
+ /* 2e */ GLFW_KEY_M,
+ /* 2f */ GLFW_KEY_PERIOD,
+ /* 30 */ GLFW_KEY_TAB,
+ /* 31 */ GLFW_KEY_SPACE,
+ /* 32 */ GLFW_KEY_WORLD_1,
+ /* 33 */ GLFW_KEY_BACKSPACE,
+ /* 34 */ -1,
+ /* 35 */ GLFW_KEY_ESCAPE,
+ /* 36 */ GLFW_KEY_RIGHT_SUPER,
+ /* 37 */ GLFW_KEY_LEFT_SUPER,
+ /* 38 */ GLFW_KEY_LEFT_SHIFT,
+ /* 39 */ GLFW_KEY_CAPS_LOCK,
+ /* 3a */ GLFW_KEY_LEFT_ALT,
+ /* 3b */ GLFW_KEY_LEFT_CONTROL,
+ /* 3c */ GLFW_KEY_RIGHT_SHIFT,
+ /* 3d */ GLFW_KEY_RIGHT_ALT,
+ /* 3e */ GLFW_KEY_RIGHT_CONTROL,
+ /* 3f */ -1, /* Function */
+ /* 40 */ GLFW_KEY_F17,
+ /* 41 */ GLFW_KEY_KP_DECIMAL,
+ /* 42 */ -1,
+ /* 43 */ GLFW_KEY_KP_MULTIPLY,
+ /* 44 */ -1,
+ /* 45 */ GLFW_KEY_KP_ADD,
+ /* 46 */ -1,
+ /* 47 */ GLFW_KEY_NUM_LOCK, /* Really KeypadClear... */
+ /* 48 */ -1, /* VolumeUp */
+ /* 49 */ -1, /* VolumeDown */
+ /* 4a */ -1, /* Mute */
+ /* 4b */ GLFW_KEY_KP_DIVIDE,
+ /* 4c */ GLFW_KEY_KP_ENTER,
+ /* 4d */ -1,
+ /* 4e */ GLFW_KEY_KP_SUBTRACT,
+ /* 4f */ GLFW_KEY_F18,
+ /* 50 */ GLFW_KEY_F19,
+ /* 51 */ GLFW_KEY_KP_EQUAL,
+ /* 52 */ GLFW_KEY_KP_0,
+ /* 53 */ GLFW_KEY_KP_1,
+ /* 54 */ GLFW_KEY_KP_2,
+ /* 55 */ GLFW_KEY_KP_3,
+ /* 56 */ GLFW_KEY_KP_4,
+ /* 57 */ GLFW_KEY_KP_5,
+ /* 58 */ GLFW_KEY_KP_6,
+ /* 59 */ GLFW_KEY_KP_7,
+ /* 5a */ GLFW_KEY_F20,
+ /* 5b */ GLFW_KEY_KP_8,
+ /* 5c */ GLFW_KEY_KP_9,
+ /* 5d */ -1,
+ /* 5e */ -1,
+ /* 5f */ -1,
+ /* 60 */ GLFW_KEY_F5,
+ /* 61 */ GLFW_KEY_F6,
+ /* 62 */ GLFW_KEY_F7,
+ /* 63 */ GLFW_KEY_F3,
+ /* 64 */ GLFW_KEY_F8,
+ /* 65 */ GLFW_KEY_F9,
+ /* 66 */ -1,
+ /* 67 */ GLFW_KEY_F11,
+ /* 68 */ -1,
+ /* 69 */ GLFW_KEY_F13,
+ /* 6a */ GLFW_KEY_F16,
+ /* 6b */ GLFW_KEY_F14,
+ /* 6c */ -1,
+ /* 6d */ GLFW_KEY_F10,
+ /* 6e */ -1,
+ /* 6f */ GLFW_KEY_F12,
+ /* 70 */ -1,
+ /* 71 */ GLFW_KEY_F15,
+ /* 72 */ GLFW_KEY_INSERT, /* Really Help... */
+ /* 73 */ GLFW_KEY_HOME,
+ /* 74 */ GLFW_KEY_PAGE_UP,
+ /* 75 */ GLFW_KEY_DELETE,
+ /* 76 */ GLFW_KEY_F4,
+ /* 77 */ GLFW_KEY_END,
+ /* 78 */ GLFW_KEY_F2,
+ /* 79 */ GLFW_KEY_PAGE_DOWN,
+ /* 7a */ GLFW_KEY_F1,
+ /* 7b */ GLFW_KEY_LEFT,
+ /* 7c */ GLFW_KEY_RIGHT,
+ /* 7d */ GLFW_KEY_DOWN,
+ /* 7e */ GLFW_KEY_UP,
+ /* 7f */ -1,
+ };
+
if (macKeyCode >= 128)
return -1;
// This treats keycodes as *positional*; that is, we'll return 'a'
// for the key left of 's', even on an AZERTY keyboard. The charInput
// function should still get 'q' though.
- return MAC_TO_GLFW_KEYCODE_MAPPING[macKeyCode];
+ return table[macKeyCode];
}
+
//========================================================================
// Content view class for the GLFW window
//========================================================================
@@ -388,11 +388,11 @@ static int convertMacKeyCode(unsigned int macKeyCode)
{
NSUInteger i, length;
NSString* characters;
- int code = convertMacKeyCode([event keyCode]);
+ int key = convertMacKeyCode([event keyCode]);
- if (code != -1)
+ if (key != -1)
{
- _glfwInputKey(window, code, GLFW_PRESS);
+ _glfwInputKey(window, key, GLFW_PRESS);
if ([event modifierFlags] & NSCommandKeyMask)
{
@@ -412,7 +412,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
- (void)flagsChanged:(NSEvent *)event
{
- int mode;
+ int mode, key;
unsigned int newModifierFlags =
[event modifierFlags] | NSDeviceIndependentModifierFlagsMask;
@@ -422,14 +422,17 @@ static int convertMacKeyCode(unsigned int macKeyCode)
mode = GLFW_RELEASE;
window->NS.modifierFlags = newModifierFlags;
- _glfwInputKey(window, MAC_TO_GLFW_KEYCODE_MAPPING[[event keyCode]], mode);
+
+ key = convertMacKeyCode([event keyCode]);
+ if (key != -1)
+ _glfwInputKey(window, key, mode);
}
- (void)keyUp:(NSEvent *)event
{
- int code = convertMacKeyCode([event keyCode]);
- if (code != -1)
- _glfwInputKey(window, code, GLFW_RELEASE);
+ int key = convertMacKeyCode([event keyCode]);
+ if (key != -1)
+ _glfwInputKey(window, key, GLFW_RELEASE);
}
- (void)scrollWheel:(NSEvent *)event
@@ -446,6 +449,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
@end
+
//========================================================================
// GLFW application class
//========================================================================
@@ -516,6 +520,7 @@ static NSString* findAppName(void)
return @"GLFW Application";
}
+
//========================================================================
// Set up the menu bar (manually)
// This is nasty, nasty stuff -- calls to undocumented semi-private APIs that
@@ -523,6 +528,7 @@ static NSString* findAppName(void)
// localize(d|able), etc. Loading a nib would save us this horror, but that
// doesn't seem like a good thing to require of GLFW's clients.
//========================================================================
+
static void createMenuBar(void)
{
NSString* appName = findAppName();
@@ -586,6 +592,7 @@ static void createMenuBar(void)
//========================================================================
// Initialize the Cocoa Application Kit
//========================================================================
+
static GLboolean initializeAppKit(void)
{
if (NSApp)
@@ -604,6 +611,7 @@ static GLboolean initializeAppKit(void)
return GL_TRUE;
}
+
//========================================================================
// Create the Cocoa window
//========================================================================
@@ -647,6 +655,7 @@ static GLboolean createWindow(_GLFWwindow* window,
return GL_TRUE;
}
+
//========================================================================
// Create the OpenGL context
//========================================================================
@@ -919,6 +928,7 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
// TODO: Probably more cleanup
}
+
//========================================================================
// Set the window title
//========================================================================
@@ -928,6 +938,7 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title)
[window->NS.window setTitle:[NSString stringWithUTF8String:title]];
}
+
//========================================================================
// Set the window size
//========================================================================
@@ -937,6 +948,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
[window->NS.window setContentSize:NSMakeSize(width, height)];
}
+
//========================================================================
// Set the window position
//========================================================================
@@ -957,6 +969,7 @@ void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y)
display:YES];
}
+
//========================================================================
// Iconify the window
//========================================================================
@@ -966,6 +979,7 @@ void _glfwPlatformIconifyWindow(_GLFWwindow* window)
[window->NS.window miniaturize:nil];
}
+
//========================================================================
// Restore (un-iconify) the window
//========================================================================
@@ -975,6 +989,7 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
[window->NS.window deminiaturize:nil];
}
+
//========================================================================
// Write back window parameters into GLFW window structure
//========================================================================
@@ -1049,6 +1064,7 @@ void _glfwPlatformRefreshWindowParams(void)
window->glDebug = GL_FALSE;
}
+
//========================================================================
// Poll for new window and input events
//========================================================================
@@ -1073,6 +1089,7 @@ void _glfwPlatformPollEvents(void)
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init];
}
+
//========================================================================
// Wait for new window and input events
//========================================================================
@@ -1091,6 +1108,7 @@ void _glfwPlatformWaitEvents( void )
_glfwPlatformPollEvents();
}
+
//========================================================================
// Set physical mouse cursor position
//========================================================================
@@ -1118,6 +1136,7 @@ void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y)
CGDisplayMoveCursorToPoint(CGMainDisplayID(), targetPoint);
}
+
//========================================================================
// Set physical mouse cursor mode
//========================================================================
diff --git a/src/input.c b/src/input.c
index ec894a279..ded88712f 100644
--- a/src/input.c
+++ b/src/input.c
@@ -167,7 +167,7 @@ void _glfwInputKey(_GLFWwindow* window, int key, int action)
return;
// Register key action
- if(action == GLFW_RELEASE && window->stickyKeys)
+ if (action == GLFW_RELEASE && window->stickyKeys)
window->key[key] = GLFW_STICK;
else
{
diff --git a/src/x11_fullscreen.c b/src/x11_fullscreen.c
index e71c2a2b3..f7855c4b3 100644
--- a/src/x11_fullscreen.c
+++ b/src/x11_fullscreen.c
@@ -372,6 +372,8 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
}
}
+ XFree(vislist);
+
rescount = 0;
resarray = NULL;
@@ -457,8 +459,6 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
}
}
- XFree(vislist);
-
free(resarray);
free(rgbarray);
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 663f9a119..7a166881c 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -36,6 +36,9 @@ target_link_libraries(joysticks ${STATIC_DEPS})
add_executable(listmodes listmodes.c)
target_link_libraries(listmodes ${STATIC_DEPS})
+add_executable(modes modes.c getopt.c)
+target_link_libraries(modes ${STATIC_DEPS})
+
add_executable(peter peter.c)
target_link_libraries(peter ${STATIC_DEPS})
@@ -64,7 +67,7 @@ set_target_properties(windows PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Windows")
set(WINDOWS_BINARIES accuracy sharing tearing title windows)
set(CONSOLE_BINARIES defaults events fsaa fsfocus gamma glfwinfo iconify
- joysticks listmodes peter reopen)
+ joysticks listmodes modes peter reopen)
if (MSVC)
# Tell MSVC to use main instead of WinMain for Windows subsystem executables
diff --git a/tests/modes.c b/tests/modes.c
new file mode 100644
index 000000000..de3aec8a3
--- /dev/null
+++ b/tests/modes.c
@@ -0,0 +1,225 @@
+//========================================================================
+// Video mode test
+// Copyright (c) Camilla Berglund
+//
+// 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
+
+#include
+#include
+
+#include "getopt.h"
+
+static GLFWwindow window = NULL;
+
+enum Mode
+{
+ NO_MODE,
+ LIST_MODE,
+ TEST_MODE
+};
+
+static void usage(void)
+{
+ printf("Usage: modes -l\n");
+ printf(" modes -t\n");
+ printf(" modes -h\n");
+}
+
+static void print_mode(GLFWvidmode* mode)
+{
+ printf("%i x %i x %i (%i %i %i)",
+ mode->width, mode->height,
+ mode->redBits + mode->greenBits + mode->blueBits,
+ mode->redBits, mode->greenBits, mode->blueBits);
+}
+
+static void error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Error: %s\n", description);
+}
+
+static void window_size_callback(GLFWwindow window, int width, int height)
+{
+ printf("Window resized to %ix%i\n", width, height);
+
+ glViewport(0, 0, width, height);
+}
+
+static int window_close_callback(GLFWwindow dummy)
+{
+ window = NULL;
+ return GL_TRUE;
+}
+
+static void list_modes(GLFWvidmode* modes, int count)
+{
+ int i;
+ GLFWvidmode mode;
+
+ glfwGetDesktopMode(&mode);
+ printf("Desktop mode: ");
+ print_mode(&mode);
+ putchar('\n');
+
+ for (i = 0; i < count; i++)
+ {
+ printf("%3i: ", i);
+ print_mode(modes + i);
+ putchar('\n');
+ }
+}
+
+static void test_modes(GLFWvidmode* modes, int count)
+{
+ int i, width, height;
+
+ glfwSetWindowSizeCallback(window_size_callback);
+ glfwSetWindowCloseCallback(window_close_callback);
+
+ for (i = 0; i < count; i++)
+ {
+ glfwOpenWindowHint(GLFW_RED_BITS, modes[i].redBits);
+ glfwOpenWindowHint(GLFW_GREEN_BITS, modes[i].greenBits);
+ glfwOpenWindowHint(GLFW_BLUE_BITS, modes[i].blueBits);
+
+ printf("Opening ");
+ print_mode(modes + i);
+ printf(" window\n");
+
+ window = glfwOpenWindow(modes[i].width, modes[i].height,
+ GLFW_FULLSCREEN, "Video Mode Test",
+ NULL);
+ if (!window)
+ {
+ printf("Failed to enter mode %i: ", i);
+ print_mode(modes + i);
+ putchar('\n');
+ continue;
+ }
+
+ glfwSetTime(0.0);
+ glfwSwapInterval(1);
+
+ while (glfwGetTime() < 5.0)
+ {
+ glClear(GL_COLOR_BUFFER_BIT);
+ glfwSwapBuffers();
+ glfwPollEvents();
+
+ if (!window)
+ {
+ printf("User terminated program\n");
+ exit(EXIT_SUCCESS);
+ }
+ }
+
+ if (glfwGetWindowParam(window, GLFW_RED_BITS) != modes[i].redBits ||
+ glfwGetWindowParam(window, GLFW_GREEN_BITS) != modes[i].greenBits ||
+ glfwGetWindowParam(window, GLFW_BLUE_BITS) != modes[i].blueBits)
+ {
+ printf("*** Color bit mismatch: (%i %i %i) instead of (%i %i %i)\n",
+ glfwGetWindowParam(window, GLFW_RED_BITS),
+ glfwGetWindowParam(window, GLFW_GREEN_BITS),
+ glfwGetWindowParam(window, GLFW_BLUE_BITS),
+ modes[i].redBits,
+ modes[i].greenBits,
+ modes[i].blueBits);
+ }
+
+ glfwGetWindowSize(window, &width, &height);
+
+ if (width != modes[i].width || height != height)
+ {
+ printf("*** Size mismatch: %ix%i instead of %ix%i\n",
+ width, height,
+ modes[i].width, modes[i].height);
+ }
+
+ printf("Closing window\n");
+
+ glfwCloseWindow(window);
+ glfwPollEvents();
+ window = NULL;
+
+ sleep(5);
+ }
+}
+
+int main(int argc, char** argv)
+{
+ int ch, found, count = 0, mode = NO_MODE;
+ GLFWvidmode* modes = NULL;
+
+ while ((ch = getopt(argc, argv, "lth")) != -1)
+ {
+ switch (ch)
+ {
+ case 'h':
+ usage();
+ exit(EXIT_SUCCESS);
+ case 'l':
+ mode = LIST_MODE;
+ break;
+ case 't':
+ mode = TEST_MODE;
+ break;
+ default:
+ usage();
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ glfwSetErrorCallback(error_callback);
+
+ if (!glfwInit())
+ exit(EXIT_FAILURE);
+
+ for (;;)
+ {
+ count += 256;
+ modes = realloc(modes, sizeof(GLFWvidmode) * count);
+
+ found = glfwGetVideoModes(modes, count);
+ if (found < count)
+ break;
+ }
+
+ if (mode == LIST_MODE)
+ list_modes(modes, found);
+ else if (mode == TEST_MODE)
+ test_modes(modes, found);
+
+ free(modes);
+ modes = NULL;
+
+ exit(EXIT_SUCCESS);
+}
+