mirror of
https://github.com/gwm17/glfw.git
synced 2025-01-31 03:18:50 -05:00
Merge branch 'master' of github.com:elmindreda/glfw
This commit is contained in:
commit
61d4cf4f39
|
@ -280,6 +280,7 @@ version of GLFW.</p>
|
||||||
<li>Added <code>windows</code> simple multi-window test program</li>
|
<li>Added <code>windows</code> simple multi-window test program</li>
|
||||||
<li>Added <code>sharing</code> simple OpenGL object sharing test program</li>
|
<li>Added <code>sharing</code> simple OpenGL object sharing test program</li>
|
||||||
<li>Added <code>dynamic</code> simple dynamic linking test program</li>
|
<li>Added <code>dynamic</code> simple dynamic linking test program</li>
|
||||||
|
<li>Added <code>modes</code> video mode enumeration and setting test program</li>
|
||||||
<li>Added a parameter to <code>glfwOpenWindow</code> for specifying a context the new window's context will share objects with</li>
|
<li>Added a parameter to <code>glfwOpenWindow</code> for specifying a context the new window's context will share objects with</li>
|
||||||
<li>Added initial window title parameter to <code>glfwOpenWindow</code></li>
|
<li>Added initial window title parameter to <code>glfwOpenWindow</code></li>
|
||||||
<li>Added <code>glfwSetGamma</code>, <code>glfwSetGammaRamp</code> and <code>glfwGetGammaRamp</code> functions and <code>GLFWgammaramp</code> type for monitor gamma ramp control</li>
|
<li>Added <code>glfwSetGamma</code>, <code>glfwSetGammaRamp</code> and <code>glfwGetGammaRamp</code> functions and <code>GLFWgammaramp</code> type for monitor gamma ramp control</li>
|
||||||
|
|
|
@ -64,6 +64,7 @@ static GLboolean modeIsGood(CGDisplayModeRef mode)
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Convert Core Graphics display mode to GLFW video mode
|
// Convert Core Graphics display mode to GLFW video mode
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -217,6 +218,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||||
return stored;
|
return stored;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Get the desktop video mode
|
// Get the desktop video mode
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Change to our application bundle's resources directory, if present
|
// Change to our application bundle's resources directory, if present
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void changeToResourcesDirectory(void)
|
static void changeToResourcesDirectory(void)
|
||||||
{
|
{
|
||||||
char resourcesPath[MAXPATHLEN];
|
char resourcesPath[MAXPATHLEN];
|
||||||
|
@ -112,6 +113,7 @@ int _glfwPlatformInit(void)
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Close window, if open, and shut down GLFW
|
// Close window, if open, and shut down GLFW
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
|
@ -579,4 +579,3 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
|
||||||
return numbuttons;
|
return numbuttons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,7 @@ void _glfwPlatformSwapBuffers(void)
|
||||||
[window->NSGL.context flushBuffer];
|
[window->NSGL.context flushBuffer];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set double buffering swap interval
|
// Set double buffering swap interval
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -71,6 +72,7 @@ void _glfwPlatformSwapInterval(int interval)
|
||||||
[window->NSGL.context setValues:&sync forParameter:NSOpenGLCPSwapInterval];
|
[window->NSGL.context setValues:&sync forParameter:NSOpenGLCPSwapInterval];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Check if an OpenGL extension is available at runtime
|
// Check if an OpenGL extension is available at runtime
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -81,6 +83,7 @@ int _glfwPlatformExtensionSupported(const char* extension)
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Get the function pointer to an OpenGL function
|
// Get the function pointer to an OpenGL function
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -99,6 +102,7 @@ void* _glfwPlatformGetProcAddress(const char* procname)
|
||||||
return symbol;
|
return symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Copies the specified OpenGL state categories from src to dst
|
// Copies the specified OpenGL state categories from src to dst
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
|
@ -74,6 +74,7 @@ double _glfwPlatformGetTime(void)
|
||||||
_glfwLibrary.NS.timer.resolution;
|
_glfwLibrary.NS.timer.resolution;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set timer value in seconds
|
// Set timer value in seconds
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
|
@ -112,6 +112,7 @@
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Delegate for application related notifications
|
// Delegate for application related notifications
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -133,13 +134,17 @@
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Keyboard symbol translation table
|
// Converts a Mac OS X keycode to a GLFW keycode
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
// TODO: Need to find mappings for F13-F15, volume down/up/mute, and eject.
|
static int convertMacKeyCode(unsigned int macKeyCode)
|
||||||
static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] =
|
|
||||||
{
|
{
|
||||||
|
// 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,
|
/* 00 */ GLFW_KEY_A,
|
||||||
/* 01 */ GLFW_KEY_S,
|
/* 01 */ GLFW_KEY_S,
|
||||||
/* 02 */ GLFW_KEY_D,
|
/* 02 */ GLFW_KEY_D,
|
||||||
|
@ -268,23 +273,18 @@ static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] =
|
||||||
/* 7d */ GLFW_KEY_DOWN,
|
/* 7d */ GLFW_KEY_DOWN,
|
||||||
/* 7e */ GLFW_KEY_UP,
|
/* 7e */ GLFW_KEY_UP,
|
||||||
/* 7f */ -1,
|
/* 7f */ -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// Converts a Mac OS X keycode to a GLFW keycode
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
static int convertMacKeyCode(unsigned int macKeyCode)
|
|
||||||
{
|
|
||||||
if (macKeyCode >= 128)
|
if (macKeyCode >= 128)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// This treats keycodes as *positional*; that is, we'll return 'a'
|
// This treats keycodes as *positional*; that is, we'll return 'a'
|
||||||
// for the key left of 's', even on an AZERTY keyboard. The charInput
|
// for the key left of 's', even on an AZERTY keyboard. The charInput
|
||||||
// function should still get 'q' though.
|
// function should still get 'q' though.
|
||||||
return MAC_TO_GLFW_KEYCODE_MAPPING[macKeyCode];
|
return table[macKeyCode];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Content view class for the GLFW window
|
// Content view class for the GLFW window
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -388,11 +388,11 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||||
{
|
{
|
||||||
NSUInteger i, length;
|
NSUInteger i, length;
|
||||||
NSString* characters;
|
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)
|
if ([event modifierFlags] & NSCommandKeyMask)
|
||||||
{
|
{
|
||||||
|
@ -412,7 +412,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||||
|
|
||||||
- (void)flagsChanged:(NSEvent *)event
|
- (void)flagsChanged:(NSEvent *)event
|
||||||
{
|
{
|
||||||
int mode;
|
int mode, key;
|
||||||
unsigned int newModifierFlags =
|
unsigned int newModifierFlags =
|
||||||
[event modifierFlags] | NSDeviceIndependentModifierFlagsMask;
|
[event modifierFlags] | NSDeviceIndependentModifierFlagsMask;
|
||||||
|
|
||||||
|
@ -422,14 +422,17 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||||
mode = GLFW_RELEASE;
|
mode = GLFW_RELEASE;
|
||||||
|
|
||||||
window->NS.modifierFlags = newModifierFlags;
|
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
|
- (void)keyUp:(NSEvent *)event
|
||||||
{
|
{
|
||||||
int code = convertMacKeyCode([event keyCode]);
|
int key = convertMacKeyCode([event keyCode]);
|
||||||
if (code != -1)
|
if (key != -1)
|
||||||
_glfwInputKey(window, code, GLFW_RELEASE);
|
_glfwInputKey(window, key, GLFW_RELEASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)scrollWheel:(NSEvent *)event
|
- (void)scrollWheel:(NSEvent *)event
|
||||||
|
@ -446,6 +449,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW application class
|
// GLFW application class
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -516,6 +520,7 @@ static NSString* findAppName(void)
|
||||||
return @"GLFW Application";
|
return @"GLFW Application";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set up the menu bar (manually)
|
// Set up the menu bar (manually)
|
||||||
// This is nasty, nasty stuff -- calls to undocumented semi-private APIs that
|
// 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
|
// 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.
|
// doesn't seem like a good thing to require of GLFW's clients.
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void createMenuBar(void)
|
static void createMenuBar(void)
|
||||||
{
|
{
|
||||||
NSString* appName = findAppName();
|
NSString* appName = findAppName();
|
||||||
|
@ -586,6 +592,7 @@ static void createMenuBar(void)
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Initialize the Cocoa Application Kit
|
// Initialize the Cocoa Application Kit
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static GLboolean initializeAppKit(void)
|
static GLboolean initializeAppKit(void)
|
||||||
{
|
{
|
||||||
if (NSApp)
|
if (NSApp)
|
||||||
|
@ -604,6 +611,7 @@ static GLboolean initializeAppKit(void)
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Create the Cocoa window
|
// Create the Cocoa window
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -647,6 +655,7 @@ static GLboolean createWindow(_GLFWwindow* window,
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Create the OpenGL context
|
// Create the OpenGL context
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -919,6 +928,7 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
|
||||||
// TODO: Probably more cleanup
|
// TODO: Probably more cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set the window title
|
// Set the window title
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -928,6 +938,7 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title)
|
||||||
[window->NS.window setTitle:[NSString stringWithUTF8String:title]];
|
[window->NS.window setTitle:[NSString stringWithUTF8String:title]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set the window size
|
// Set the window size
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -937,6 +948,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
|
||||||
[window->NS.window setContentSize:NSMakeSize(width, height)];
|
[window->NS.window setContentSize:NSMakeSize(width, height)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set the window position
|
// Set the window position
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -957,6 +969,7 @@ void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y)
|
||||||
display:YES];
|
display:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Iconify the window
|
// Iconify the window
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -966,6 +979,7 @@ void _glfwPlatformIconifyWindow(_GLFWwindow* window)
|
||||||
[window->NS.window miniaturize:nil];
|
[window->NS.window miniaturize:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Restore (un-iconify) the window
|
// Restore (un-iconify) the window
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -975,6 +989,7 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
|
||||||
[window->NS.window deminiaturize:nil];
|
[window->NS.window deminiaturize:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Write back window parameters into GLFW window structure
|
// Write back window parameters into GLFW window structure
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -1049,6 +1064,7 @@ void _glfwPlatformRefreshWindowParams(void)
|
||||||
window->glDebug = GL_FALSE;
|
window->glDebug = GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Poll for new window and input events
|
// Poll for new window and input events
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -1073,6 +1089,7 @@ void _glfwPlatformPollEvents(void)
|
||||||
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init];
|
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Wait for new window and input events
|
// Wait for new window and input events
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -1091,6 +1108,7 @@ void _glfwPlatformWaitEvents( void )
|
||||||
_glfwPlatformPollEvents();
|
_glfwPlatformPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set physical mouse cursor position
|
// Set physical mouse cursor position
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -1118,6 +1136,7 @@ void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y)
|
||||||
CGDisplayMoveCursorToPoint(CGMainDisplayID(), targetPoint);
|
CGDisplayMoveCursorToPoint(CGMainDisplayID(), targetPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set physical mouse cursor mode
|
// Set physical mouse cursor mode
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
|
@ -167,7 +167,7 @@ void _glfwInputKey(_GLFWwindow* window, int key, int action)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Register key action
|
// Register key action
|
||||||
if(action == GLFW_RELEASE && window->stickyKeys)
|
if (action == GLFW_RELEASE && window->stickyKeys)
|
||||||
window->key[key] = GLFW_STICK;
|
window->key[key] = GLFW_STICK;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -372,6 +372,8 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XFree(vislist);
|
||||||
|
|
||||||
rescount = 0;
|
rescount = 0;
|
||||||
resarray = NULL;
|
resarray = NULL;
|
||||||
|
|
||||||
|
@ -457,8 +459,6 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XFree(vislist);
|
|
||||||
|
|
||||||
free(resarray);
|
free(resarray);
|
||||||
free(rgbarray);
|
free(rgbarray);
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,9 @@ target_link_libraries(joysticks ${STATIC_DEPS})
|
||||||
add_executable(listmodes listmodes.c)
|
add_executable(listmodes listmodes.c)
|
||||||
target_link_libraries(listmodes ${STATIC_DEPS})
|
target_link_libraries(listmodes ${STATIC_DEPS})
|
||||||
|
|
||||||
|
add_executable(modes modes.c getopt.c)
|
||||||
|
target_link_libraries(modes ${STATIC_DEPS})
|
||||||
|
|
||||||
add_executable(peter peter.c)
|
add_executable(peter peter.c)
|
||||||
target_link_libraries(peter ${STATIC_DEPS})
|
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(WINDOWS_BINARIES accuracy sharing tearing title windows)
|
||||||
set(CONSOLE_BINARIES defaults events fsaa fsfocus gamma glfwinfo iconify
|
set(CONSOLE_BINARIES defaults events fsaa fsfocus gamma glfwinfo iconify
|
||||||
joysticks listmodes peter reopen)
|
joysticks listmodes modes peter reopen)
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
# Tell MSVC to use main instead of WinMain for Windows subsystem executables
|
# Tell MSVC to use main instead of WinMain for Windows subsystem executables
|
||||||
|
|
225
tests/modes.c
Normal file
225
tests/modes.c
Normal file
|
@ -0,0 +1,225 @@
|
||||||
|
//========================================================================
|
||||||
|
// Video mode test
|
||||||
|
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
||||||
|
//
|
||||||
|
// 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 <GL/glfw3.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user