Formatting pass.

This commit is contained in:
Camilla Berglund 2010-09-10 22:03:36 +02:00
parent 484a2714fc
commit 479c9255fc
7 changed files with 725 additions and 876 deletions

View File

@ -31,10 +31,6 @@
#include "internal.h"
//************************************************************************
//**** GLFW internal functions ****
//************************************************************************
//========================================================================
// Low level keyboard hook (system callback) function
// Used to disable system keys under Windows NT
@ -84,9 +80,7 @@ static LRESULT CALLBACK keyboardHook( int nCode, WPARAM wParam, LPARAM lParam )
{
// Pass the key event to our window message loop
if (_glfwWin.opened)
{
PostMessage(_glfwWin.window, (UINT) wParam, p->vkCode, 0);
}
// We've taken care of it - don't let the system know about this
// key event
@ -100,10 +94,9 @@ static LRESULT CALLBACK keyboardHook( int nCode, WPARAM wParam, LPARAM lParam )
}
//************************************************************************
//**** Platform implementation functions ****
//************************************************************************
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Enable system keys
@ -123,11 +116,10 @@ void _glfwPlatformEnableSystemKeys( void )
}
}
else
{
(void) SystemParametersInfo( SPI_SETSCREENSAVERRUNNING, FALSE, &dummy, 0 );
}
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, FALSE, &dummy, 0);
}
//========================================================================
// Disable system keys
//========================================================================
@ -149,7 +141,7 @@ void _glfwPlatformDisableSystemKeys( void )
{
// Under Windows 95/98/ME, fool Windows that a screensaver
// is running => prevents ALT+TAB, CTRL+ESC and CTRL+ALT+DEL
(void) SystemParametersInfo( SPI_SETSCREENSAVERRUNNING, TRUE, &dummy, 0 );
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, TRUE, &dummy, 0);
}
}

View File

@ -31,10 +31,6 @@
#include "internal.h"
//************************************************************************
//**** GLFW internal functions ****
//************************************************************************
//========================================================================
// Convert BPP to RGB bits based on "best guess"
//========================================================================
@ -45,25 +41,51 @@ static void bpp2rgb( int bpp, int *r, int *g, int *b )
// We assume that by 32 they really meant 24
if (bpp == 32)
{
bpp = 24;
}
// Convert "bits per pixel" to red, green & blue sizes
*r = *g = *b = bpp / 3;
delta = bpp - (*r * 3);
if (delta >= 1)
{
*g = *g + 1;
}
if (delta == 2)
{
*r = *r + 1;
}
//========================================================================
// Return closest video mode by dimensions, refresh rate and channel sizes
//========================================================================
static int getClosestVideoMode(int* w, int* h,
int* r, int* g, int* b,
int* refresh)
{
int bpp, bestmode;
// Colorbits = sum of red/green/blue bits
bpp = *r + *g + *b;
// If colorbits < 15 (e.g. 0) or >= 24, default to 32 bpp
if (bpp < 15 || bpp >= 24)
bpp = 32;
// Find best match
bestmode = _glfwGetClosestVideoModeBPP(w, h, &bpp, refresh);
// Convert "bits per pixel" to red, green & blue sizes
bpp2rgb(bpp, r, g, b);
return bestmode;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Return closest video mode by dimensions, refresh rate and bits per pixel
//========================================================================
@ -77,6 +99,7 @@ int _glfwGetClosestVideoModeBPP( int *w, int *h, int *bpp, int *refresh )
bestmatch = 0x7fffffff;
bestrr = 0x7fffffff;
mode = bestmode = 0;
do
{
dm.dmSize = sizeof(DEVMODE);
@ -84,7 +107,9 @@ int _glfwGetClosestVideoModeBPP( int *w, int *h, int *bpp, int *refresh )
if (success)
{
match = dm.dmBitsPerPel - *bpp;
if( match < 0 ) match = -match;
if (match < 0)
match = -match;
match = (match << 25) |
((dm.dmPelsWidth - *w) *
(dm.dmPelsWidth - *w) +
@ -115,7 +140,7 @@ int _glfwGetClosestVideoModeBPP( int *w, int *h, int *bpp, int *refresh )
// Get the parameters for the best matching display mode
dm.dmSize = sizeof(DEVMODE);
(void) EnumDisplaySettings( NULL, bestmode, &dm );
EnumDisplaySettings(NULL, bestmode, &dm);
// Fill out actual width and height
*w = dm.dmPelsWidth;
@ -131,35 +156,6 @@ int _glfwGetClosestVideoModeBPP( int *w, int *h, int *bpp, int *refresh )
}
//========================================================================
// Return closest video mode by dimensions, refresh rate and channel sizes
//========================================================================
static int getClosestVideoMode( int *w, int *h,
int *r, int *g, int *b,
int *refresh )
{
int bpp, bestmode;
// Colorbits = sum of red/green/blue bits
bpp = *r + *g + *b;
// If colorbits < 15 (e.g. 0) or >= 24, default to 32 bpp
if( bpp < 15 || bpp >= 24 )
{
bpp = 32;
}
// Find best match
bestmode = _glfwGetClosestVideoModeBPP( w, h, &bpp, refresh );
// Convert "bits per pixel" to red, green & blue sizes
bpp2rgb( bpp, r, g, b );
return bestmode;
}
//========================================================================
// Change the current video mode
//========================================================================
@ -171,7 +167,7 @@ void _glfwSetVideoModeMODE( int mode )
// Get the parameters for the best matching display mode
dm.dmSize = sizeof(DEVMODE);
(void) EnumDisplaySettings( NULL, mode, &dm );
EnumDisplaySettings(NULL, mode, &dm);
// Set which fields we want to specify
dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
@ -190,9 +186,7 @@ void _glfwSetVideoModeMODE( int mode )
// If the mode change was not possible, query the current display
// settings (we'll use the desktop resolution for fullscreen mode)
if (success == DISP_CHANGE_SUCCESSFUL)
{
_glfwWin.modeID = mode;
}
else
{
_glfwWin.modeID = ENUM_REGISTRY_SETTINGS;
@ -221,9 +215,9 @@ void _glfwSetVideoMode( int *w, int *h, int r, int g, int b, int refresh )
}
//************************************************************************
//**** GLFW user functions ****
//************************************************************************
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Get a list of available video modes
@ -238,6 +232,7 @@ int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )
// Loop through all video modes and extract all the UNIQUE modes
count = 0;
mode = 0;
do
{
// Get video mode properties
@ -258,14 +253,11 @@ int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )
for (i = 0; i < count; i++)
{
// Mode "code" for already listed mode
bpp = list[i].redBits + list[i].greenBits +
list[i].blueBits;
bpp = list[i].redBits + list[i].greenBits + list[i].blueBits;
m2 = (bpp << 25) | (list[i].width * list[i].height);
if (m1 <= m2)
{
break;
}
}
// New entry at the end of the list?
if (i >= count)
@ -281,9 +273,8 @@ int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )
else if (m1 < m2)
{
for (j = count; j > i; j--)
{
list[j] = list[j - 1];
}
list[i].width = dm.dmPelsWidth;
list[i].height = dm.dmPelsHeight;
list[i].redBits = r;
@ -310,7 +301,7 @@ void _glfwPlatformGetDesktopMode( GLFWvidmode *mode )
// Get desktop display mode
dm.dmSize = sizeof(DEVMODE);
(void) EnumDisplaySettings( NULL, ENUM_REGISTRY_SETTINGS, &dm );
EnumDisplaySettings(NULL, ENUM_REGISTRY_SETTINGS, &dm);
// Return desktop mode parameters
mode->width = dm.dmPelsWidth;

View File

@ -31,9 +31,9 @@
#include "internal.h"
//************************************************************************
//**** Platform implementation functions ****
//************************************************************************
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Check if the current context supports the specified WGL extension
@ -49,11 +49,9 @@ int _glfwPlatformExtensionSupported( const char *extension )
if (extensions != NULL)
{
if (_glfwStringInExtensionString(extension, extensions))
{
return GL_TRUE;
}
}
}
if (_glfwWin.GetExtensionsStringARB != NULL)
{
@ -61,11 +59,9 @@ int _glfwPlatformExtensionSupported( const char *extension )
if (extensions != NULL)
{
if (_glfwStringInExtensionString(extension, extensions))
{
return GL_TRUE;
}
}
}
return GL_FALSE;
}

View File

@ -36,16 +36,11 @@
#endif // __BORLANDC__
//************************************************************************
//**** GLFW internal functions ****
//************************************************************************
//========================================================================
// Load necessary libraries (DLLs)
//========================================================================
static int _glfwInitLibraries( void )
static GLboolean initLibraries(void)
{
// gdi32.dll (OpenGL pixel format functions & SwapBuffers)
#ifndef _GLFW_NO_DLOAD_GDI32
@ -62,11 +57,12 @@ static int _glfwInitLibraries( void )
GetProcAddress(_glfwLibrary.Libs.gdi32, "SetPixelFormat");
_glfwLibrary.Libs.SwapBuffers = (SWAPBUFFERS_T)
GetProcAddress(_glfwLibrary.Libs.gdi32, "SwapBuffers");
if( _glfwLibrary.Libs.ChoosePixelFormat == NULL ||
_glfwLibrary.Libs.DescribePixelFormat == NULL ||
_glfwLibrary.Libs.GetPixelFormat == NULL ||
_glfwLibrary.Libs.SetPixelFormat == NULL ||
_glfwLibrary.Libs.SwapBuffers == NULL )
if (_glfwLibrary.Libs.ChoosePixelFormat &&
_glfwLibrary.Libs.DescribePixelFormat &&
_glfwLibrary.Libs.GetPixelFormat &&
_glfwLibrary.Libs.SetPixelFormat &&
_glfwLibrary.Libs.SwapBuffers)
{
FreeLibrary(_glfwLibrary.Libs.gdi32);
_glfwLibrary.Libs.gdi32 = NULL;
@ -74,9 +70,7 @@ static int _glfwInitLibraries( void )
}
}
else
{
return GL_FALSE;
}
#endif // _GLFW_NO_DLOAD_GDI32
// winmm.dll (for joystick and timer support)
@ -92,10 +86,11 @@ static int _glfwInitLibraries( void )
GetProcAddress(_glfwLibrary.Libs.winmm, "joyGetPosEx");
_glfwLibrary.Libs.timeGetTime = (TIMEGETTIME_T)
GetProcAddress(_glfwLibrary.Libs.winmm, "timeGetTime");
if( _glfwLibrary.Libs.joyGetDevCapsA == NULL ||
_glfwLibrary.Libs.joyGetPos == NULL ||
_glfwLibrary.Libs.joyGetPosEx == NULL ||
_glfwLibrary.Libs.timeGetTime == NULL )
if (_glfwLibrary.Libs.joyGetDevCapsA &&
_glfwLibrary.Libs.joyGetPos &&
_glfwLibrary.Libs.joyGetPosEx &&
_glfwLibrary.Libs.timeGetTime)
{
FreeLibrary(_glfwLibrary.Libs.winmm);
_glfwLibrary.Libs.winmm = NULL;
@ -103,9 +98,7 @@ static int _glfwInitLibraries( void )
}
}
else
{
return GL_FALSE;
}
#endif // _GLFW_NO_DLOAD_WINMM
return GL_TRUE;
@ -116,7 +109,7 @@ static int _glfwInitLibraries( void )
// Unload used libraries (DLLs)
//========================================================================
static void _glfwFreeLibraries( void )
static void freeLibraries(void)
{
// gdi32.dll
#ifndef _GLFW_NO_DLOAD_GDI32
@ -142,16 +135,15 @@ static void _glfwFreeLibraries( void )
// Terminate GLFW when exiting application
//========================================================================
void _glfwTerminate_atexit( void )
static void glfw_atexit(void)
{
glfwTerminate();
}
//************************************************************************
//**** Platform implementation functions ****
//************************************************************************
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Initialize various GLFW state
@ -172,49 +164,33 @@ int _glfwPlatformInit( void )
// Check which OS version we are running
osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osi);
_glfwLibrary.Sys.winVer = _GLFW_WIN_UNKNOWN;
if (osi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
{
if (osi.dwMajorVersion == 4 && osi.dwMinorVersion < 10)
{
_glfwLibrary.Sys.winVer = _GLFW_WIN_95;
}
else if (osi.dwMajorVersion == 4 && osi.dwMinorVersion < 90)
{
_glfwLibrary.Sys.winVer = _GLFW_WIN_98;
}
else if (osi.dwMajorVersion == 4 && osi.dwMinorVersion == 90)
{
_glfwLibrary.Sys.winVer = _GLFW_WIN_ME;
}
else if (osi.dwMajorVersion >= 4)
{
_glfwLibrary.Sys.winVer = _GLFW_WIN_UNKNOWN_9x;
}
}
else if (osi.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
if (osi.dwMajorVersion == 4 && osi.dwMinorVersion == 0)
{
_glfwLibrary.Sys.winVer = _GLFW_WIN_NT4;
}
else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 0)
{
_glfwLibrary.Sys.winVer = _GLFW_WIN_2K;
}
else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 1)
{
_glfwLibrary.Sys.winVer = _GLFW_WIN_XP;
}
else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 2)
{
_glfwLibrary.Sys.winVer = _GLFW_WIN_NET_SERVER;
}
else if (osi.dwMajorVersion >= 5)
{
_glfwLibrary.Sys.winVer = _GLFW_WIN_UNKNOWN_NT;
}
}
// Do we have Unicode support?
if (_glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4)
@ -230,9 +206,7 @@ int _glfwPlatformInit( void )
// Load libraries (DLLs)
if (!_glfwInitLibraries())
{
return GL_FALSE;
}
// With the Borland C++ compiler, we want to disable FPU exceptions
// (this is recommended for OpenGL applications under Windows)
@ -247,7 +221,7 @@ int _glfwPlatformInit( void )
_glfwWin.keyboardHook = NULL;
// Install atexit() routine
atexit( _glfwTerminate_atexit );
atexit(glfw_atexit);
// Start the timer
_glfwInitTimer();

View File

@ -31,36 +31,30 @@
#include "internal.h"
//************************************************************************
//**** GLFW internal functions ****
//************************************************************************
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Return GL_TRUE if joystick is present, else return GL_FALSE.
//========================================================================
static int _glfwJoystickPresent( int joy )
static GLboolean isJoystickPresent(int joy)
{
JOYINFO ji;
// Windows NT 4.0 MMSYSTEM only supports 2 sticks (other Windows
// versions support 16 sticks)
if (_glfwLibrary.Sys.winVer == _GLFW_WIN_NT4 && joy > GLFW_JOYSTICK_2)
{
return GL_FALSE;
}
// Is it a valid stick ID (Windows don't support more than 16 sticks)?
if (joy < GLFW_JOYSTICK_1 || joy > GLFW_JOYSTICK_16)
{
return GL_FALSE;
}
// Is the joystick present?
if (_glfw_joyGetPos(joy - GLFW_JOYSTICK_1, &ji) != JOYERR_NOERROR)
{
return GL_FALSE;
}
return GL_TRUE;
}
@ -70,19 +64,19 @@ static int _glfwJoystickPresent( int joy )
// Calculate joystick position
//========================================================================
static float _glfwCalcJoystickPos( DWORD pos, DWORD min, DWORD max )
static float calcJoystickPos(DWORD pos, DWORD min, DWORD max)
{
float fpos = (float) pos;
float fmin = (float) min;
float fmax = (float) max;
return (2.0f*(fpos - fmin) / (fmax - fmin)) - 1.0f;
return (2.f * (fpos - fmin) / (fmax - fmin)) - 1.f;
}
//************************************************************************
//**** Platform implementation functions ****
//************************************************************************
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Determine joystick capabilities
@ -92,19 +86,12 @@ int _glfwPlatformGetJoystickParam( int joy, int param )
{
JOYCAPS jc;
// return 0;
// Is joystick present?
if( !_glfwJoystickPresent( joy ) )
{
if (!isJoystickPresent(joy))
return 0;
}
// We got this far, the joystick is present
if (param == GLFW_PRESENT)
{
return GL_TRUE;
}
// Get joystick capabilities
_glfw_joyGetDevCaps(joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS));
@ -137,13 +124,8 @@ int _glfwPlatformGetJoystickPos( int joy, float *pos, int numaxes )
JOYINFOEX ji;
int axis;
// return 0;
// Is joystick present?
if( !_glfwJoystickPresent( joy ) )
{
if (!isJoystickPresent(joy))
return 0;
}
// Get joystick capabilities
_glfw_joyGetDevCaps(joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS));
@ -157,37 +139,23 @@ int _glfwPlatformGetJoystickPos( int joy, float *pos, int numaxes )
// Get position values for all axes
axis = 0;
if (axis < numaxes)
{
pos[ axis++ ] = _glfwCalcJoystickPos( ji.dwXpos, jc.wXmin,
jc.wXmax );
}
if( axis < numaxes )
{
pos[ axis++ ] = -_glfwCalcJoystickPos( ji.dwYpos, jc.wYmin,
jc.wYmax );
}
if( axis < numaxes && jc.wCaps & JOYCAPS_HASZ )
{
pos[ axis++ ] = _glfwCalcJoystickPos( ji.dwZpos, jc.wZmin,
jc.wZmax );
}
if( axis < numaxes && jc.wCaps & JOYCAPS_HASR )
{
pos[ axis++ ] = _glfwCalcJoystickPos( ji.dwRpos, jc.wRmin,
jc.wRmax );
}
if( axis < numaxes && jc.wCaps & JOYCAPS_HASU )
{
pos[ axis++ ] = _glfwCalcJoystickPos( ji.dwUpos, jc.wUmin,
jc.wUmax );
}
if( axis < numaxes && jc.wCaps & JOYCAPS_HASV )
{
pos[ axis++ ] = -_glfwCalcJoystickPos( ji.dwVpos, jc.wVmin,
jc.wVmax );
}
pos[axis++] = _glfwCalcJoystickPos(ji.dwXpos, jc.wXmin, jc.wXmax);
if (axis < numaxes)
pos[axis++] = -_glfwCalcJoystickPos(ji.dwYpos, jc.wYmin, jc.wYmax);
if (axis < numaxes && jc.wCaps & JOYCAPS_HASZ)
pos[axis++] = _glfwCalcJoystickPos(ji.dwZpos, jc.wZmin, jc.wZmax);
if (axis < numaxes && jc.wCaps & JOYCAPS_HASR)
pos[axis++] = _glfwCalcJoystickPos(ji.dwRpos, jc.wRmin, jc.wRmax);
if (axis < numaxes && jc.wCaps & JOYCAPS_HASU)
pos[axis++] = _glfwCalcJoystickPos(ji.dwUpos, jc.wUmin, jc.wUmax);
if (axis < numaxes && jc.wCaps & JOYCAPS_HASV)
pos[axis++] = -_glfwCalcJoystickPos(ji.dwVpos, jc.wVmin, jc.wVmax);
// Return number of returned axes
return axis;
}
@ -203,13 +171,8 @@ int _glfwPlatformGetJoystickButtons( int joy, unsigned char *buttons,
JOYINFOEX ji;
int button;
// return 0;
// Is joystick present?
if( !_glfwJoystickPresent( joy ) )
{
if (!isJoystickPresent(joy))
return 0;
}
// Get joystick capabilities
_glfw_joyGetDevCaps(joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS));

View File

@ -31,9 +31,9 @@
#include "internal.h"
//************************************************************************
//**** GLFW internal functions ****
//************************************************************************
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Initialise timer
@ -69,9 +69,9 @@ void _glfwInitTimer( void )
}
//************************************************************************
//**** Platform implementation functions ****
//************************************************************************
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Return timer value in seconds
@ -88,9 +88,7 @@ double _glfwPlatformGetTime( void )
t = (double)(t_64 - _glfwLibrary.Timer.t0_64);
}
else
{
t = (double)(_glfw_timeGetTime() - _glfwLibrary.Timer.t0_32);
}
// Calculate the current time in seconds
return t * _glfwLibrary.Timer.Resolution;
@ -111,8 +109,6 @@ void _glfwPlatformSetTime( double t )
_glfwLibrary.Timer.t0_64 = t_64 - (__int64) (t / _glfwLibrary.Timer.Resolution);
}
else
{
_glfwLibrary.Timer.t0_32 = _glfw_timeGetTime() - (int)(t * 1000.0);
}
}

View File

@ -31,14 +31,9 @@
#include "internal.h"
//************************************************************************
//**** GLFW internal functions ****
//************************************************************************
// We use versioned window class names in order not to cause conflicts
// between applications using different versions of GLFW
#define _GLFW_WNDCLASSNAME "GLFW27"
#define _GLFW_WNDCLASSNAME "GLFW30"
//========================================================================
@ -120,7 +115,7 @@ static void setForegroundWindow( HWND hWnd )
while (hWnd != GetForegroundWindow() && try_count <= 3);
// Restore the system minimize/restore animation setting
(void) setMinMaxAnimations( old_animate );
setMinMaxAnimations(old_animate);
// Try to modify the system settings (since this is now hopefully the
// foreground process, we are probably allowed to do this)
@ -161,13 +156,9 @@ static _GLFWfbconfig *getFBConfigs( unsigned int *found )
*found = 0;
if (_glfwWin.has_WGL_ARB_pixel_format)
{
count = getPixelFormatAttrib(1, WGL_NUMBER_PIXEL_FORMATS_ARB);
}
else
{
count = _glfw_DescribePixelFormat(_glfwWin.DC, 1, sizeof(PIXELFORMATDESCRIPTOR), NULL);
}
if (!count)
{
@ -178,7 +169,7 @@ static _GLFWfbconfig *getFBConfigs( unsigned int *found )
result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count);
if (!result)
{
fprintf(stderr, "Out of memory");
fprintf(stderr, "Out of memory\n");
return NULL;
}
@ -188,19 +179,17 @@ static _GLFWfbconfig *getFBConfigs( unsigned int *found )
{
// Get pixel format attributes through WGL_ARB_pixel_format
// Only consider doublebuffered OpenGL pixel formats for windows
if (!getPixelFormatAttrib(i, WGL_SUPPORT_OPENGL_ARB) ||
!getPixelFormatAttrib(i, WGL_DRAW_TO_WINDOW_ARB) ||
!getPixelFormatAttrib(i, WGL_DOUBLE_BUFFER_ARB))
{
// Only consider doublebuffered OpenGL pixel formats for windows
continue;
}
if( getPixelFormatAttrib( i, WGL_PIXEL_TYPE_ARB ) != WGL_TYPE_RGBA_ARB )
{
// Only consider RGBA pixel formats
if (getPixelFormatAttrib(i, WGL_PIXEL_TYPE_ARB) != WGL_TYPE_RGBA_ARB)
continue;
}
result[*found].redBits = getPixelFormatAttrib(i, WGL_RED_BITS_ARB);
result[*found].greenBits = getPixelFormatAttrib(i, WGL_GREEN_BITS_ARB);
@ -219,28 +208,22 @@ static _GLFWfbconfig *getFBConfigs( unsigned int *found )
result[*found].stereo = getPixelFormatAttrib(i, WGL_STEREO_ARB);
if (_glfwWin.has_WGL_ARB_multisample)
{
result[*found].samples = getPixelFormatAttrib(i, WGL_SAMPLES_ARB);
}
else
{
result[*found].samples = 0;
}
}
else
{
// Get pixel format attributes through old-fashioned PFDs
if (!_glfw_DescribePixelFormat(_glfwWin.DC, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd))
{
continue;
}
// Only consider doublebuffered OpenGL pixel formats for windows
if (!(pfd.dwFlags & PFD_DRAW_TO_WINDOW) ||
!(pfd.dwFlags & PFD_SUPPORT_OPENGL) ||
!(pfd.dwFlags & PFD_DOUBLEBUFFER))
{
// Only consider doublebuffered OpenGL pixel formats for windows
continue;
}
@ -250,11 +233,9 @@ static _GLFWfbconfig *getFBConfigs( unsigned int *found )
continue;
}
if( pfd.iPixelType != PFD_TYPE_RGBA )
{
// Only RGBA pixel formats considered
if (pfd.iPixelType != PFD_TYPE_RGBA)
continue;
}
result[*found].redBits = pfd.cRedBits;
result[*found].greenBits = pfd.cGreenBits;
@ -295,14 +276,10 @@ static HGLRC createContext( HDC dc, const _GLFWwndconfig* wndconfig, int pixelFo
int flags, i = 0, attribs[7];
if (!_glfw_DescribePixelFormat(dc, pixelFormat, sizeof(pfd), &pfd))
{
return NULL;
}
if (!_glfw_SetPixelFormat(dc, pixelFormat, &pfd))
{
return NULL;
}
if (_glfwWin.has_WGL_ARB_create_context)
{
@ -323,14 +300,10 @@ static HGLRC createContext( HDC dc, const _GLFWwndconfig* wndconfig, int pixelFo
flags = 0;
if (wndconfig->glForward)
{
flags |= WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
}
if (wndconfig->glDebug)
{
flags |= WGL_CONTEXT_DEBUG_BIT_ARB;
}
attribs[i++] = WGL_CONTEXT_FLAGS_ARB;
attribs[i++] = flags;
@ -339,13 +312,9 @@ static HGLRC createContext( HDC dc, const _GLFWwndconfig* wndconfig, int pixelFo
if (wndconfig->glProfile)
{
if (wndconfig->glProfile == GLFW_OPENGL_CORE_PROFILE)
{
flags = WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
}
else
{
flags = WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
}
attribs[i++] = WGL_CONTEXT_PROFILE_MASK_ARB;
attribs[i++] = flags;
@ -408,9 +377,7 @@ static int translateKey( WPARAM wParam, LPARAM lParam )
// right)
scan_code = MapVirtualKey(VK_RSHIFT, 0);
if (((lParam & 0x01ff0000) >> 16) == scan_code)
{
return GLFW_KEY_RSHIFT;
}
return GLFW_KEY_LSHIFT;
}
@ -420,9 +387,7 @@ static int translateKey( WPARAM wParam, LPARAM lParam )
{
// Is this an extended key (i.e. right key)?
if (lParam & 0x01000000)
{
return GLFW_KEY_RCTRL;
}
// Here is a trick: "Alt Gr" sends LCTRL, then RALT. We only
// want the RALT message, so we try to see if the next message
@ -452,9 +417,7 @@ static int translateKey( WPARAM wParam, LPARAM lParam )
{
// Is this an extended key (i.e. right key)?
if (lParam & 0x01000000)
{
return GLFW_KEY_RALT;
}
return GLFW_KEY_LALT;
}
@ -464,9 +427,7 @@ static int translateKey( WPARAM wParam, LPARAM lParam )
{
// Is this an extended key (i.e. right key)?
if (lParam & 0x01000000)
{
return GLFW_KEY_KP_ENTER;
}
return GLFW_KEY_ENTER;
}
@ -545,13 +506,9 @@ static int translateKey( WPARAM wParam, LPARAM lParam )
// Make sure that the character is uppercase
if (_glfwLibrary.Sys.hasUnicode)
{
wParam = (WPARAM) CharUpperW((LPWSTR) wParam);
}
else
{
wParam = (WPARAM) CharUpperA((LPSTR) wParam);
}
// Valid ISO-8859-1 character?
if ((wParam >= 32 && wParam <= 126) ||
@ -617,15 +574,11 @@ static void translateChar( DWORD wParam, DWORD lParam, int action )
{
// Get next character from buffer
if (unicode)
{
_glfwInputChar((int) unicode_buf[i], action);
}
else
{
_glfwInputChar((int) char_buf[i], action);
}
}
}
//========================================================================
@ -698,9 +651,8 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg,
// Lock mouse, if necessary
if (_glfwWin.oldMouseLockValid && _glfwWin.oldMouseLock)
{
glfwDisable(GLFW_MOUSE_CURSOR);
}
_glfwWin.oldMouseLockValid = GL_FALSE;
}
@ -717,15 +669,13 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg,
{
if (_glfwWin.fullscreen)
{
// Disallow screen saver and screen blanking if we are
// running in fullscreen mode
// We are running in fullscreen mode, so disallow
// screen saver and screen blanking
return 0;
}
else
{
break;
}
}
// User trying to access application menu using ALT?
case SC_KEYMENU:
@ -748,9 +698,8 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg,
_glfwInputKey(translateKey(wParam, lParam), GLFW_PRESS);
if (_glfwWin.charCallback)
{
translateChar((DWORD) wParam, (DWORD) lParam, GLFW_PRESS);
}
return 0;
}
@ -764,30 +713,35 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg,
_glfwInputKey(GLFW_KEY_RSHIFT, GLFW_RELEASE);
}
else
{
_glfwInputKey(translateKey(wParam, lParam), GLFW_RELEASE);
}
if (_glfwWin.charCallback)
{
translateChar((DWORD) wParam, (DWORD) lParam, GLFW_RELEASE);
}
return 0;
}
case WM_LBUTTONDOWN:
{
SetCapture(hWnd);
_glfwInputMouseClick(GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS);
return 0;
}
case WM_RBUTTONDOWN:
{
SetCapture(hWnd);
_glfwInputMouseClick(GLFW_MOUSE_BUTTON_RIGHT, GLFW_PRESS);
return 0;
}
case WM_MBUTTONDOWN:
{
SetCapture(hWnd);
_glfwInputMouseClick(GLFW_MOUSE_BUTTON_MIDDLE, GLFW_PRESS);
return 0;
}
case WM_XBUTTONDOWN:
{
if (HIWORD(wParam) == XBUTTON1)
@ -800,21 +754,31 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg,
SetCapture(hWnd);
_glfwInputMouseClick(GLFW_MOUSE_BUTTON_5, GLFW_PRESS);
}
return 1;
}
case WM_LBUTTONUP:
{
ReleaseCapture();
_glfwInputMouseClick(GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE);
return 0;
}
case WM_RBUTTONUP:
{
ReleaseCapture();
_glfwInputMouseClick(GLFW_MOUSE_BUTTON_RIGHT, GLFW_RELEASE);
return 0;
}
case WM_MBUTTONUP:
{
ReleaseCapture();
_glfwInputMouseClick(GLFW_MOUSE_BUTTON_MIDDLE, GLFW_RELEASE);
return 0;
}
case WM_XBUTTONUP:
{
if (HIWORD(wParam) == XBUTTON1)
@ -827,6 +791,7 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg,
ReleaseCapture();
_glfwInputMouseClick(GLFW_MOUSE_BUTTON_5, GLFW_RELEASE);
}
return 1;
}
@ -853,6 +818,7 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg,
_glfwInput.MousePosX = NewMouseX;
_glfwInput.MousePosY = NewMouseY;
}
_glfwInput.OldMouseX = NewMouseX;
_glfwInput.OldMouseY = NewMouseY;
_glfwInput.MouseMoved = GL_TRUE;
@ -863,6 +829,7 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg,
_glfwInput.MousePosY);
}
}
return 0;
}
@ -873,10 +840,10 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg,
{
wheelDelta = (((int)wParam) >> 16) / WHEEL_DELTA;
_glfwInput.WheelPos += wheelDelta;
if (_glfwWin.mouseWheelCallback)
{
_glfwWin.mouseWheelCallback(_glfwInput.WheelPos);
}
return 0;
}
break;
@ -892,15 +859,12 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg,
{
RECT ClipWindowRect;
if (GetWindowRect(_glfwWin.window, &ClipWindowRect))
{
ClipCursor(&ClipWindowRect);
}
}
if (_glfwWin.windowSizeCallback)
{
_glfwWin.windowSizeCallback(LOWORD(lParam), HIWORD(lParam));
}
return 0;
}
@ -911,10 +875,8 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg,
{
RECT ClipWindowRect;
if (GetWindowRect(_glfwWin.window, &ClipWindowRect))
{
ClipCursor(&ClipWindowRect);
}
}
return 0;
}
@ -922,9 +884,8 @@ static LRESULT CALLBACK windowProc( HWND hWnd, UINT uMsg,
case WM_PAINT:
{
if (_glfwWin.windowRefreshCallback)
{
_glfwWin.windowRefreshCallback();
}
break;
}
@ -996,15 +957,11 @@ static void initWGLExtensions( void )
_glfwWin.GetExtensionsStringARB = (WGLGETEXTENSIONSSTRINGARB_T)
wglGetProcAddress("wglGetExtensionsStringARB");
if (!_glfwWin.GetExtensionsStringARB)
{
return;
}
}
if (_glfwPlatformExtensionSupported("WGL_ARB_multisample"))
{
_glfwWin.has_WGL_ARB_multisample = GL_TRUE;
}
if (_glfwPlatformExtensionSupported("WGL_ARB_create_context"))
{
@ -1155,13 +1112,9 @@ static int createWindow( const _GLFWwndconfig *wndconfig,
// the top of the display). Fullscreen windows are always opened in
// the upper left corner regardless of the desktop working area.
if (_glfwWin.fullscreen)
{
wa.left = wa.top = 0;
}
else
{
SystemParametersInfo(SPI_GETWORKAREA, 0, &wa, 0);
}
_glfwWin.window = CreateWindowEx(_glfwWin.dwExStyle, // Extended style
_GLFW_WNDCLASSNAME, // Class name
@ -1255,9 +1208,9 @@ static void destroyWindow( void )
//************************************************************************
//**** Platform implementation functions ****
//************************************************************************
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Here is where the window is created, and the OpenGL rendering context is
@ -1393,7 +1346,7 @@ void _glfwPlatformCloseWindow( void )
void _glfwPlatformSetWindowTitle(const char* title)
{
(void) SetWindowText( _glfwWin.window, title );
SetWindowText(_glfwWin.window, title);
}
@ -1427,10 +1380,8 @@ void _glfwPlatformSetWindowSize( int width, int height )
&refresh);
}
else
{
mode = _glfwWin.modeID;
}
}
else
{
// If we are in windowed mode, adjust the window size to
@ -1538,9 +1489,8 @@ void _glfwPlatformRestoreWindow( void )
// Lock mouse, if necessary
if (_glfwWin.oldMouseLockValid && _glfwWin.oldMouseLock)
{
glfwDisable(GLFW_MOUSE_CURSOR);
}
_glfwWin.oldMouseLockValid = GL_FALSE;
}
@ -1562,10 +1512,8 @@ void _glfwPlatformSwapBuffers( void )
void _glfwPlatformSwapInterval(int interval)
{
if (_glfwWin.has_WGL_EXT_swap_control)
{
_glfwWin.SwapIntervalEXT(interval);
}
}
//========================================================================
@ -1589,9 +1537,7 @@ void _glfwPlatformRefreshWindowParams( void )
_glfwWin.accelerated = GL_TRUE;
}
else
{
_glfwWin.accelerated = GL_FALSE;
}
_glfwWin.redBits = getPixelFormatAttrib(pixelFormat, WGL_RED_BITS_ARB);
_glfwWin.greenBits = getPixelFormatAttrib(pixelFormat, WGL_GREEN_BITS_ARB);
@ -1615,10 +1561,8 @@ void _glfwPlatformRefreshWindowParams( void )
// Should we force 1 to 0 here for consistency, or keep 1 for transparency?
}
else
{
_glfwWin.samples = 0;
}
}
else
{
_glfw_DescribePixelFormat(_glfwWin.DC, pixelFormat,
@ -1655,15 +1599,11 @@ void _glfwPlatformRefreshWindowParams( void )
{
_glfwWin.refreshRate = dm.dmDisplayFrequency;
if (_glfwWin.refreshRate <= 1)
{
_glfwWin.refreshRate = 0;
}
}
else
{
_glfwWin.refreshRate = 0;
}
}
//========================================================================
@ -1696,15 +1636,19 @@ void _glfwPlatformPollEvents( void )
{
// QUIT-message (from close window)?
case WM_QUIT:
{
winclosed = GL_TRUE;
break;
}
// Ok, send it to the window message handler
default:
{
DispatchMessage(&msg);
break;
}
}
}
// LSHIFT/RSHIFT fixup (keys tend to "stick" without this fix)
// This is the only async event handling in GLFW, but it solves some
@ -1721,14 +1665,11 @@ void _glfwPlatformPollEvents( void )
// See if this differs from our belief of what has happened
// (we only have to check for lost key up events)
if (!lshift_down && _glfwInput.Key[ GLFW_KEY_LSHIFT ] == 1)
{
_glfwInputKey(GLFW_KEY_LSHIFT, GLFW_RELEASE);
}
if (!rshift_down && _glfwInput.Key[ GLFW_KEY_RSHIFT ] == 1)
{
_glfwInputKey(GLFW_KEY_RSHIFT, GLFW_RELEASE);
}
}
// Did we have mouse movement in locked cursor mode?
if (_glfwInput.MouseMoved && _glfwWin.mouseLock)
@ -1744,10 +1685,8 @@ void _glfwPlatformPollEvents( void )
winclosed = _glfwWin.windowCloseCallback();
}
if (winclosed)
{
glfwCloseWindow();
}
}
//========================================================================
@ -1774,9 +1713,7 @@ void _glfwPlatformHideMouseCursor( void )
// Clip cursor to the window
if (GetWindowRect(_glfwWin.window, &ClipWindowRect))
{
ClipCursor(&ClipWindowRect);
}
// Capture cursor to user window
SetCapture(_glfwWin.window);