mirror of
				https://github.com/glfw/glfw.git
				synced 2025-11-04 14:16:42 +00: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>sharing</code> simple OpenGL object sharing 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 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>
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
//========================================================================
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
//========================================================================
 | 
			
		||||
 | 
			
		||||
@ -579,4 +579,3 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
 | 
			
		||||
    return numbuttons;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
//========================================================================
 | 
			
		||||
 | 
			
		||||
@ -74,6 +74,7 @@ double _glfwPlatformGetTime(void)
 | 
			
		||||
        _glfwLibrary.NS.timer.resolution;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//========================================================================
 | 
			
		||||
// Set timer value in seconds
 | 
			
		||||
//========================================================================
 | 
			
		||||
 | 
			
		||||
@ -112,6 +112,7 @@
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//========================================================================
 | 
			
		||||
// Delegate for application related notifications
 | 
			
		||||
//========================================================================
 | 
			
		||||
@ -133,12 +134,16 @@
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//========================================================================
 | 
			
		||||
// Keyboard symbol translation table
 | 
			
		||||
// Converts a Mac OS X keycode to a GLFW keycode
 | 
			
		||||
//========================================================================
 | 
			
		||||
 | 
			
		||||
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 MAC_TO_GLFW_KEYCODE_MAPPING[128] =
 | 
			
		||||
    static const unsigned int table[128] =
 | 
			
		||||
    {
 | 
			
		||||
        /* 00 */ GLFW_KEY_A,
 | 
			
		||||
        /* 01 */ GLFW_KEY_S,
 | 
			
		||||
@ -270,21 +275,16 @@ static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] =
 | 
			
		||||
        /* 7f */ -1,
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
//========================================================================
 | 
			
		||||
// Converts a Mac OS X keycode to a GLFW keycode
 | 
			
		||||
//========================================================================
 | 
			
		||||
 | 
			
		||||
static int convertMacKeyCode(unsigned int macKeyCode)
 | 
			
		||||
{
 | 
			
		||||
    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
 | 
			
		||||
//========================================================================
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										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