1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-22 18:28:52 -05:00

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,16 +31,12 @@
#include "internal.h"
//************************************************************************
//**** GLFW internal functions ****
//************************************************************************
//========================================================================
// Low level keyboard hook (system callback) function
// Used to disable system keys under Windows NT
//========================================================================
static LRESULT CALLBACK keyboardHook( int nCode, WPARAM wParam, LPARAM lParam )
static LRESULT CALLBACK keyboardHook(int nCode, WPARAM wParam, LPARAM lParam)
{
BOOL syskeys = FALSE;
PKBDLLHOOKSTRUCT p;
@ -49,11 +45,11 @@ static LRESULT CALLBACK keyboardHook( int nCode, WPARAM wParam, LPARAM lParam )
// pointer to a KBDLLHOOKSTRUCT
p = (PKBDLLHOOKSTRUCT) lParam;
if( nCode == HC_ACTION )
if (nCode == HC_ACTION)
{
// We have a keyboard event
switch( wParam )
switch (wParam)
{
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
@ -61,14 +57,14 @@ static LRESULT CALLBACK keyboardHook( int nCode, WPARAM wParam, LPARAM lParam )
case WM_SYSKEYUP:
// Detect: ALT+TAB, ALT+ESC, ALT+F4, CTRL+ESC,
// LWIN, RWIN, APPS (mysterious menu key)
syskeys = ( p->vkCode == VK_TAB &&
p->flags & LLKHF_ALTDOWN ) ||
( p->vkCode == VK_ESCAPE &&
p->flags & LLKHF_ALTDOWN ) ||
( p->vkCode == VK_F4 &&
p->flags & LLKHF_ALTDOWN ) ||
( p->vkCode == VK_ESCAPE &&
(GetKeyState(VK_CONTROL) & 0x8000)) ||
syskeys = (p->vkCode == VK_TAB &&
p->flags & LLKHF_ALTDOWN) ||
(p->vkCode == VK_ESCAPE &&
p->flags & LLKHF_ALTDOWN) ||
(p->vkCode == VK_F4 &&
p->flags & LLKHF_ALTDOWN) ||
(p->vkCode == VK_ESCAPE &&
(GetKeyState(VK_CONTROL) & 0x8000)) ||
p->vkCode == VK_LWIN ||
p->vkCode == VK_RWIN ||
p->vkCode == VK_APPS;
@ -80,13 +76,11 @@ static LRESULT CALLBACK keyboardHook( int nCode, WPARAM wParam, LPARAM lParam )
}
// Was it a system key combination (e.g. ALT+TAB)?
if( syskeys )
if (syskeys)
{
// Pass the key event to our window message loop
if( _glfwWin.opened )
{
PostMessage( _glfwWin.window, (UINT) wParam, p->vkCode, 0 );
}
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
@ -95,61 +89,59 @@ static LRESULT CALLBACK keyboardHook( int nCode, WPARAM wParam, LPARAM lParam )
else
{
// It's a harmless key press, let the system deal with it
return CallNextHookEx( _glfwWin.keyboardHook, nCode, wParam, lParam );
return CallNextHookEx(_glfwWin.keyboardHook, nCode, wParam, lParam);
}
}
//************************************************************************
//**** Platform implementation functions ****
//************************************************************************
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Enable system keys
//========================================================================
void _glfwPlatformEnableSystemKeys( void )
void _glfwPlatformEnableSystemKeys(void)
{
BOOL dummy;
// Use different methods depending on operating system version
if( _glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4 )
if (_glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4)
{
if( _glfwWin.keyboardHook != NULL )
if (_glfwWin.keyboardHook != NULL)
{
UnhookWindowsHookEx( _glfwWin.keyboardHook );
UnhookWindowsHookEx(_glfwWin.keyboardHook);
_glfwWin.keyboardHook = NULL;
}
}
else
{
(void) SystemParametersInfo( SPI_SETSCREENSAVERRUNNING, FALSE, &dummy, 0 );
}
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, FALSE, &dummy, 0);
}
//========================================================================
// Disable system keys
//========================================================================
void _glfwPlatformDisableSystemKeys( void )
void _glfwPlatformDisableSystemKeys(void)
{
BOOL dummy;
// Use different methods depending on operating system version
if( _glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4 )
if (_glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4)
{
// Under Windows NT, install a low level keyboard hook
_glfwWin.keyboardHook = SetWindowsHookEx( WH_KEYBOARD_LL,
keyboardHook,
_glfwLibrary.instance,
0 );
_glfwWin.keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL,
keyboardHook,
_glfwLibrary.instance,
0);
}
else
{
// 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,77 +31,102 @@
#include "internal.h"
//************************************************************************
//**** GLFW internal functions ****
//************************************************************************
//========================================================================
// Convert BPP to RGB bits based on "best guess"
//========================================================================
static void bpp2rgb( int bpp, int *r, int *g, int *b )
static void bpp2rgb(int bpp, int* r, int* g, int* b)
{
int delta;
// We assume that by 32 they really meant 24
if( bpp == 32 )
{
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 )
{
if (delta >= 1)
*g = *g + 1;
}
if( delta == 2 )
{
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
//========================================================================
int _glfwGetClosestVideoModeBPP( int *w, int *h, int *bpp, int *refresh )
int _glfwGetClosestVideoModeBPP(int* w, int* h, int* bpp, int* refresh)
{
int mode, bestmode, match, bestmatch, rr, bestrr, success;
int mode, bestmode, match, bestmatch, rr, bestrr, success;
DEVMODE dm;
// Find best match
bestmatch = 0x7fffffff;
bestrr = 0x7fffffff;
mode = bestmode = 0;
do
{
dm.dmSize = sizeof( DEVMODE );
success = EnumDisplaySettings( NULL, mode, &dm );
if( success )
dm.dmSize = sizeof(DEVMODE);
success = EnumDisplaySettings(NULL, mode, &dm);
if (success)
{
match = dm.dmBitsPerPel - *bpp;
if( match < 0 ) match = -match;
match = ( match << 25 ) |
( (dm.dmPelsWidth - *w) *
(dm.dmPelsWidth - *w) +
(dm.dmPelsHeight - *h) *
(dm.dmPelsHeight - *h) );
if( match < bestmatch )
if (match < 0)
match = -match;
match = (match << 25) |
((dm.dmPelsWidth - *w) *
(dm.dmPelsWidth - *w) +
(dm.dmPelsHeight - *h) *
(dm.dmPelsHeight - *h));
if (match < bestmatch)
{
bestmatch = match;
bestmode = mode;
bestrr = (dm.dmDisplayFrequency - *refresh) *
(dm.dmDisplayFrequency - *refresh);
}
else if( match == bestmatch && *refresh > 0 )
else if (match == bestmatch && *refresh > 0)
{
rr = (dm.dmDisplayFrequency - *refresh) *
(dm.dmDisplayFrequency - *refresh);
if( rr < bestrr )
if (rr < bestrr)
{
bestmatch = match;
bestmode = mode;
@ -109,13 +134,13 @@ int _glfwGetClosestVideoModeBPP( int *w, int *h, int *bpp, int *refresh )
}
}
}
mode ++;
mode++;
}
while( success );
while (success);
// Get the parameters for the best matching display mode
dm.dmSize = sizeof( DEVMODE );
(void) EnumDisplaySettings( NULL, bestmode, &dm );
dm.dmSize = sizeof(DEVMODE);
EnumDisplaySettings(NULL, bestmode, &dm);
// Fill out actual width and height
*w = dm.dmPelsWidth;
@ -131,72 +156,41 @@ 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
//========================================================================
void _glfwSetVideoModeMODE( int mode )
void _glfwSetVideoModeMODE(int mode)
{
DEVMODE dm;
int success;
// Get the parameters for the best matching display mode
dm.dmSize = sizeof( DEVMODE );
(void) EnumDisplaySettings( NULL, mode, &dm );
dm.dmSize = sizeof(DEVMODE);
EnumDisplaySettings(NULL, mode, &dm);
// Set which fields we want to specify
dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
// Do we have a prefered refresh rate?
if( _glfwWin.desiredRefreshRate > 0 )
if (_glfwWin.desiredRefreshRate > 0)
{
dm.dmFields = dm.dmFields | DM_DISPLAYFREQUENCY;
dm.dmDisplayFrequency = _glfwWin.desiredRefreshRate;
}
// Change display setting
dm.dmSize = sizeof( DEVMODE );
success = ChangeDisplaySettings( &dm, CDS_FULLSCREEN );
dm.dmSize = sizeof(DEVMODE);
success = ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
// 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 )
{
if (success == DISP_CHANGE_SUCCESSFUL)
_glfwWin.modeID = mode;
}
else
{
_glfwWin.modeID = ENUM_REGISTRY_SETTINGS;
EnumDisplaySettings( NULL, ENUM_REGISTRY_SETTINGS, &dm );
EnumDisplaySettings(NULL, ENUM_REGISTRY_SETTINGS, &dm);
}
// Set the window size to that of the display mode
@ -209,27 +203,27 @@ void _glfwSetVideoModeMODE( int mode )
// Change the current video mode
//========================================================================
void _glfwSetVideoMode( int *w, int *h, int r, int g, int b, int refresh )
void _glfwSetVideoMode(int* w, int* h, int r, int g, int b, int refresh)
{
int bestmode;
int bestmode;
// Find a best match mode
bestmode = getClosestVideoMode( w, h, &r, &g, &b, &refresh );
bestmode = getClosestVideoMode(w, h, &r, &g, &b, &refresh);
// Change mode
_glfwSetVideoModeMODE( bestmode );
_glfwSetVideoModeMODE(bestmode);
}
//************************************************************************
//**** GLFW user functions ****
//************************************************************************
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Get a list of available video modes
//========================================================================
int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )
int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
{
int count, success, mode, i, j;
int m1, m2, bpp, r, g, b;
@ -238,37 +232,35 @@ 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
dm.dmSize = sizeof( DEVMODE );
success = EnumDisplaySettings( NULL, mode, &dm );
dm.dmSize = sizeof(DEVMODE);
success = EnumDisplaySettings(NULL, mode, &dm);
// Is it a valid mode? (only list depths >= 15 bpp)
if( success && dm.dmBitsPerPel >= 15 )
if (success && dm.dmBitsPerPel >= 15)
{
// Convert to RGB, and back to bpp ("mask out" alpha bits etc)
bpp2rgb( dm.dmBitsPerPel, &r, &g, &b );
bpp2rgb(dm.dmBitsPerPel, &r, &g, &b);
bpp = r + g + b;
// Mode "code" for this mode
m1 = (bpp << 25) | (dm.dmPelsWidth * dm.dmPelsHeight);
// Insert mode in list (sorted), and avoid duplicates
for( i = 0; i < count; i ++ )
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 )
{
if (m1 <= m2)
break;
}
}
// New entry at the end of the list?
if( i >= count )
if (i >= count)
{
list[count].width = dm.dmPelsWidth;
list[count].height = dm.dmPelsHeight;
@ -278,23 +270,22 @@ int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )
count ++;
}
// Insert new entry in the list?
else if( m1 < m2 )
else if (m1 < m2)
{
for( j = count; j > i; j -- )
{
list[j] = list[j-1];
}
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;
list[i].greenBits = g;
list[i].blueBits = b;
count ++;
count++;
}
}
mode ++;
mode++;
}
while( success && (count < maxcount) );
while (success && (count < maxcount));
return count;
}
@ -304,17 +295,17 @@ int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )
// Get the desktop video mode
//========================================================================
void _glfwPlatformGetDesktopMode( GLFWvidmode *mode )
void _glfwPlatformGetDesktopMode(GLFWvidmode* mode)
{
DEVMODE dm;
// Get desktop display mode
dm.dmSize = sizeof( DEVMODE );
(void) EnumDisplaySettings( NULL, ENUM_REGISTRY_SETTINGS, &dm );
dm.dmSize = sizeof(DEVMODE);
EnumDisplaySettings(NULL, ENUM_REGISTRY_SETTINGS, &dm);
// Return desktop mode parameters
mode->width = dm.dmPelsWidth;
mode->height = dm.dmPelsHeight;
bpp2rgb( dm.dmBitsPerPel, &mode->redBits, &mode->greenBits, &mode->blueBits );
bpp2rgb(dm.dmBitsPerPel, &mode->redBits, &mode->greenBits, &mode->blueBits);
}

View File

@ -31,39 +31,35 @@
#include "internal.h"
//************************************************************************
//**** Platform implementation functions ****
//************************************************************************
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Check if the current context supports the specified WGL extension
//========================================================================
int _glfwPlatformExtensionSupported( const char *extension )
int _glfwPlatformExtensionSupported(const char* extension)
{
const GLubyte *extensions;
const GLubyte* extensions;
if( _glfwWin.GetExtensionsStringEXT != NULL )
if (_glfwWin.GetExtensionsStringEXT != NULL)
{
extensions = (GLubyte *) _glfwWin.GetExtensionsStringEXT();
if( extensions != NULL )
extensions = (GLubyte*) _glfwWin.GetExtensionsStringEXT();
if (extensions != NULL)
{
if( _glfwStringInExtensionString( extension, extensions ) )
{
if (_glfwStringInExtensionString(extension, extensions))
return GL_TRUE;
}
}
}
if( _glfwWin.GetExtensionsStringARB != NULL )
if (_glfwWin.GetExtensionsStringARB != NULL)
{
extensions = (GLubyte *) _glfwWin.GetExtensionsStringARB( _glfwWin.DC );
if( extensions != NULL )
extensions = (GLubyte*) _glfwWin.GetExtensionsStringARB(_glfwWin.DC);
if (extensions != NULL)
{
if( _glfwStringInExtensionString( extension, extensions ) )
{
if (_glfwStringInExtensionString(extension, extensions))
return GL_TRUE;
}
}
}
@ -75,8 +71,8 @@ int _glfwPlatformExtensionSupported( const char *extension )
// Get the function pointer to an OpenGL function
//========================================================================
void *_glfwPlatformGetProcAddress( const char *procname )
void* _glfwPlatformGetProcAddress(const char* procname)
{
return (void *) wglGetProcAddress( procname );
return (void*) wglGetProcAddress(procname);
}

View File

@ -36,76 +36,69 @@
#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
_glfwLibrary.Libs.gdi32 = LoadLibrary( "gdi32.dll" );
if( _glfwLibrary.Libs.gdi32 != NULL )
_glfwLibrary.Libs.gdi32 = LoadLibrary("gdi32.dll");
if (_glfwLibrary.Libs.gdi32 != NULL)
{
_glfwLibrary.Libs.ChoosePixelFormat = (CHOOSEPIXELFORMAT_T)
GetProcAddress( _glfwLibrary.Libs.gdi32, "ChoosePixelFormat" );
_glfwLibrary.Libs.ChoosePixelFormat = (CHOOSEPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Libs.gdi32, "ChoosePixelFormat");
_glfwLibrary.Libs.DescribePixelFormat = (DESCRIBEPIXELFORMAT_T)
GetProcAddress( _glfwLibrary.Libs.gdi32, "DescribePixelFormat" );
_glfwLibrary.Libs.GetPixelFormat = (GETPIXELFORMAT_T)
GetProcAddress( _glfwLibrary.Libs.gdi32, "GetPixelFormat" );
_glfwLibrary.Libs.SetPixelFormat = (SETPIXELFORMAT_T)
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 )
GetProcAddress(_glfwLibrary.Libs.gdi32, "DescribePixelFormat");
_glfwLibrary.Libs.GetPixelFormat = (GETPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Libs.gdi32, "GetPixelFormat");
_glfwLibrary.Libs.SetPixelFormat = (SETPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Libs.gdi32, "SetPixelFormat");
_glfwLibrary.Libs.SwapBuffers = (SWAPBUFFERS_T)
GetProcAddress(_glfwLibrary.Libs.gdi32, "SwapBuffers");
if (_glfwLibrary.Libs.ChoosePixelFormat &&
_glfwLibrary.Libs.DescribePixelFormat &&
_glfwLibrary.Libs.GetPixelFormat &&
_glfwLibrary.Libs.SetPixelFormat &&
_glfwLibrary.Libs.SwapBuffers)
{
FreeLibrary( _glfwLibrary.Libs.gdi32 );
FreeLibrary(_glfwLibrary.Libs.gdi32);
_glfwLibrary.Libs.gdi32 = NULL;
return GL_FALSE;
}
}
else
{
return GL_FALSE;
}
#endif // _GLFW_NO_DLOAD_GDI32
// winmm.dll (for joystick and timer support)
#ifndef _GLFW_NO_DLOAD_WINMM
_glfwLibrary.Libs.winmm = LoadLibrary( "winmm.dll" );
if( _glfwLibrary.Libs.winmm != NULL )
_glfwLibrary.Libs.winmm = LoadLibrary("winmm.dll");
if (_glfwLibrary.Libs.winmm != NULL)
{
_glfwLibrary.Libs.joyGetDevCapsA = (JOYGETDEVCAPSA_T)
GetProcAddress( _glfwLibrary.Libs.winmm, "joyGetDevCapsA" );
_glfwLibrary.Libs.joyGetPos = (JOYGETPOS_T)
GetProcAddress( _glfwLibrary.Libs.winmm, "joyGetPos" );
_glfwLibrary.Libs.joyGetPosEx = (JOYGETPOSEX_T)
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 )
GetProcAddress(_glfwLibrary.Libs.winmm, "joyGetDevCapsA");
_glfwLibrary.Libs.joyGetPos = (JOYGETPOS_T)
GetProcAddress(_glfwLibrary.Libs.winmm, "joyGetPos");
_glfwLibrary.Libs.joyGetPosEx = (JOYGETPOSEX_T)
GetProcAddress(_glfwLibrary.Libs.winmm, "joyGetPosEx");
_glfwLibrary.Libs.timeGetTime = (TIMEGETTIME_T)
GetProcAddress(_glfwLibrary.Libs.winmm, "timeGetTime");
if (_glfwLibrary.Libs.joyGetDevCapsA &&
_glfwLibrary.Libs.joyGetPos &&
_glfwLibrary.Libs.joyGetPosEx &&
_glfwLibrary.Libs.timeGetTime)
{
FreeLibrary( _glfwLibrary.Libs.winmm );
FreeLibrary(_glfwLibrary.Libs.winmm);
_glfwLibrary.Libs.winmm = NULL;
return GL_FALSE;
}
}
else
{
return GL_FALSE;
}
#endif // _GLFW_NO_DLOAD_WINMM
return GL_TRUE;
@ -116,22 +109,22 @@ static int _glfwInitLibraries( void )
// Unload used libraries (DLLs)
//========================================================================
static void _glfwFreeLibraries( void )
static void freeLibraries(void)
{
// gdi32.dll
#ifndef _GLFW_NO_DLOAD_GDI32
if( _glfwLibrary.Libs.gdi32 != NULL )
if (_glfwLibrary.Libs.gdi32 != NULL)
{
FreeLibrary( _glfwLibrary.Libs.gdi32 );
FreeLibrary(_glfwLibrary.Libs.gdi32);
_glfwLibrary.Libs.gdi32 = NULL;
}
#endif // _GLFW_NO_DLOAD_GDI32
// winmm.dll
#ifndef _GLFW_NO_DLOAD_WINMM
if( _glfwLibrary.Libs.winmm != NULL )
if (_glfwLibrary.Libs.winmm != NULL)
{
FreeLibrary( _glfwLibrary.Libs.winmm );
FreeLibrary(_glfwLibrary.Libs.winmm);
_glfwLibrary.Libs.winmm = NULL;
}
#endif // _GLFW_NO_DLOAD_WINMM
@ -142,82 +135,65 @@ 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
//========================================================================
int _glfwPlatformInit( void )
int _glfwPlatformInit(void)
{
OSVERSIONINFO osi;
// To make SetForegroundWindow() work as we want, we need to fiddle
// with the FOREGROUNDLOCKTIMEOUT system setting (we do this as early
// as possible in the hope of still being the foreground process)
SystemParametersInfo( SPI_GETFOREGROUNDLOCKTIMEOUT, 0,
&_glfwLibrary.Sys.foregroundLockTimeout, 0 );
SystemParametersInfo( SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID)0,
SPIF_SENDCHANGE );
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0,
&_glfwLibrary.Sys.foregroundLockTimeout, 0);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) 0,
SPIF_SENDCHANGE);
// Check which OS version we are running
osi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
GetVersionEx( &osi );
osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osi);
_glfwLibrary.Sys.winVer = _GLFW_WIN_UNKNOWN;
if( osi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS )
if (osi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
{
if( osi.dwMajorVersion == 4 && osi.dwMinorVersion < 10 )
{
if (osi.dwMajorVersion == 4 && osi.dwMinorVersion < 10)
_glfwLibrary.Sys.winVer = _GLFW_WIN_95;
}
else if( osi.dwMajorVersion == 4 && osi.dwMinorVersion < 90 )
{
else if (osi.dwMajorVersion == 4 && osi.dwMinorVersion < 90)
_glfwLibrary.Sys.winVer = _GLFW_WIN_98;
}
else if( osi.dwMajorVersion == 4 && osi.dwMinorVersion == 90 )
{
else if (osi.dwMajorVersion == 4 && osi.dwMinorVersion == 90)
_glfwLibrary.Sys.winVer = _GLFW_WIN_ME;
}
else if( osi.dwMajorVersion >= 4 )
{
else if (osi.dwMajorVersion >= 4)
_glfwLibrary.Sys.winVer = _GLFW_WIN_UNKNOWN_9x;
}
}
else if( osi.dwPlatformId == VER_PLATFORM_WIN32_NT )
else if (osi.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
if( osi.dwMajorVersion == 4 && osi.dwMinorVersion == 0 )
{
if (osi.dwMajorVersion == 4 && osi.dwMinorVersion == 0)
_glfwLibrary.Sys.winVer = _GLFW_WIN_NT4;
}
else if( osi.dwMajorVersion == 5 && osi.dwMinorVersion == 0 )
{
else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 0)
_glfwLibrary.Sys.winVer = _GLFW_WIN_2K;
}
else if( osi.dwMajorVersion == 5 && osi.dwMinorVersion == 1 )
{
else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 1)
_glfwLibrary.Sys.winVer = _GLFW_WIN_XP;
}
else if( osi.dwMajorVersion == 5 && osi.dwMinorVersion == 2 )
{
else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 2)
_glfwLibrary.Sys.winVer = _GLFW_WIN_NET_SERVER;
}
else if( osi.dwMajorVersion >= 5 )
{
else if (osi.dwMajorVersion >= 5)
_glfwLibrary.Sys.winVer = _GLFW_WIN_UNKNOWN_NT;
}
}
// Do we have Unicode support?
if( _glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4 )
if (_glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4)
{
// Windows NT/2000/XP/.NET has Unicode support
_glfwLibrary.Sys.hasUnicode = GL_TRUE;
@ -229,25 +205,23 @@ int _glfwPlatformInit( void )
}
// Load libraries (DLLs)
if( !_glfwInitLibraries() )
{
if (!_glfwInitLibraries())
return GL_FALSE;
}
// With the Borland C++ compiler, we want to disable FPU exceptions
// (this is recommended for OpenGL applications under Windows)
#ifdef __BORLANDC__
_control87( MCW_EM, MCW_EM );
_control87(MCW_EM, MCW_EM);
#endif
// Retrieve GLFW instance handle
_glfwLibrary.instance = GetModuleHandle( NULL );
_glfwLibrary.instance = GetModuleHandle(NULL);
// System keys are not disabled
_glfwWin.keyboardHook = NULL;
// Install atexit() routine
atexit( _glfwTerminate_atexit );
atexit(glfw_atexit);
// Start the timer
_glfwInitTimer();
@ -260,21 +234,21 @@ int _glfwPlatformInit( void )
// Close window and shut down library
//========================================================================
int _glfwPlatformTerminate( void )
int _glfwPlatformTerminate(void)
{
// Close OpenGL window
glfwCloseWindow();
// Enable system keys again (if they were disabled)
glfwEnable( GLFW_SYSTEM_KEYS );
glfwEnable(GLFW_SYSTEM_KEYS);
// Unload libraries (DLLs)
_glfwFreeLibraries();
// Restore FOREGROUNDLOCKTIMEOUT system setting
SystemParametersInfo( SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
(LPVOID)_glfwLibrary.Sys.foregroundLockTimeout,
SPIF_SENDCHANGE );
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
(LPVOID) _glfwLibrary.Sys.foregroundLockTimeout,
SPIF_SENDCHANGE);
return GL_TRUE;
}

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 )
{
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 )
{
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 )
{
if (_glfw_joyGetPos(joy - GLFW_JOYSTICK_1, &ji) != JOYERR_NOERROR)
return GL_FALSE;
}
return GL_TRUE;
}
@ -70,57 +64,50 @@ 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
//========================================================================
int _glfwPlatformGetJoystickParam( int joy, int param )
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 )
{
if (param == GLFW_PRESENT)
return GL_TRUE;
}
// Get joystick capabilities
_glfw_joyGetDevCaps( joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS) );
_glfw_joyGetDevCaps(joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS));
switch( param )
switch (param)
{
case GLFW_AXES:
// Return number of joystick axes
return jc.wNumAxes;
case GLFW_AXES:
// Return number of joystick axes
return jc.wNumAxes;
case GLFW_BUTTONS:
// Return number of joystick axes
return jc.wNumButtons;
case GLFW_BUTTONS:
// Return number of joystick axes
return jc.wNumButtons;
default:
break;
default:
break;
}
return 0;
@ -131,63 +118,44 @@ int _glfwPlatformGetJoystickParam( int joy, int param )
// Get joystick axis positions
//========================================================================
int _glfwPlatformGetJoystickPos( int joy, float *pos, int numaxes )
int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes)
{
JOYCAPS jc;
JOYCAPS jc;
JOYINFOEX ji;
int axis;
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) );
_glfw_joyGetDevCaps(joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS));
// Get joystick state
ji.dwSize = sizeof( JOYINFOEX );
ji.dwSize = sizeof(JOYINFOEX);
ji.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNZ |
JOY_RETURNR | JOY_RETURNU | JOY_RETURNV;
_glfw_joyGetPosEx( joy - GLFW_JOYSTICK_1, &ji );
_glfw_joyGetPosEx(joy - GLFW_JOYSTICK_1, &ji);
// 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 );
}
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);
// Return number of returned axes
return axis;
}
@ -196,36 +164,31 @@ int _glfwPlatformGetJoystickPos( int joy, float *pos, int numaxes )
// Get joystick button states
//========================================================================
int _glfwPlatformGetJoystickButtons( int joy, unsigned char *buttons,
int numbuttons )
int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
int numbuttons)
{
JOYCAPS jc;
JOYCAPS jc;
JOYINFOEX ji;
int button;
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) );
_glfw_joyGetDevCaps(joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS));
// Get joystick state
ji.dwSize = sizeof( JOYINFOEX );
ji.dwSize = sizeof(JOYINFOEX);
ji.dwFlags = JOY_RETURNBUTTONS;
_glfw_joyGetPosEx( joy - GLFW_JOYSTICK_1, &ji );
_glfw_joyGetPosEx(joy - GLFW_JOYSTICK_1, &ji);
// Get states of all requested buttons
button = 0;
while( button < numbuttons && button < (int) jc.wNumButtons )
while (button < numbuttons && button < (int) jc.wNumButtons)
{
buttons[ button ] = (unsigned char)
buttons[button] = (unsigned char)
(ji.dwButtons & (1UL << button) ? GLFW_PRESS : GLFW_RELEASE);
button ++;
button++;
}
return button;

View File

@ -31,29 +31,29 @@
#include "internal.h"
//************************************************************************
//**** GLFW internal functions ****
//************************************************************************
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Initialise timer
//========================================================================
void _glfwInitTimer( void )
void _glfwInitTimer(void)
{
__int64 freq;
// Check if we have a performance counter
if( QueryPerformanceFrequency( (LARGE_INTEGER *)&freq ) )
if (QueryPerformanceFrequency((LARGE_INTEGER*) &freq))
{
// Performance counter is available => use it!
_glfwLibrary.Timer.HasPerformanceCounter = GL_TRUE;
// Counter resolution is 1 / counter frequency
_glfwLibrary.Timer.Resolution = 1.0 / (double)freq;
_glfwLibrary.Timer.Resolution = 1.0 / (double) freq;
// Set start time for timer
QueryPerformanceCounter( (LARGE_INTEGER *)&_glfwLibrary.Timer.t0_64 );
QueryPerformanceCounter((LARGE_INTEGER*) &_glfwLibrary.Timer.t0_64);
}
else
{
@ -69,28 +69,26 @@ void _glfwInitTimer( void )
}
//************************************************************************
//**** Platform implementation functions ****
//************************************************************************
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Return timer value in seconds
//========================================================================
double _glfwPlatformGetTime( void )
double _glfwPlatformGetTime(void)
{
double t;
double t;
__int64 t_64;
if( _glfwLibrary.Timer.HasPerformanceCounter )
if (_glfwLibrary.Timer.HasPerformanceCounter)
{
QueryPerformanceCounter( (LARGE_INTEGER *)&t_64 );
QueryPerformanceCounter((LARGE_INTEGER*) &t_64);
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;
@ -101,18 +99,16 @@ double _glfwPlatformGetTime( void )
// Set timer value in seconds
//========================================================================
void _glfwPlatformSetTime( double t )
void _glfwPlatformSetTime(double t)
{
__int64 t_64;
if( _glfwLibrary.Timer.HasPerformanceCounter )
if (_glfwLibrary.Timer.HasPerformanceCounter)
{
QueryPerformanceCounter( (LARGE_INTEGER *)&t_64 );
_glfwLibrary.Timer.t0_64 = t_64 - (__int64)(t/_glfwLibrary.Timer.Resolution);
QueryPerformanceCounter((LARGE_INTEGER*) &t_64);
_glfwLibrary.Timer.t0_64 = t_64 - (__int64) (t / _glfwLibrary.Timer.Resolution);
}
else
{
_glfwLibrary.Timer.t0_32 = _glfw_timeGetTime() - (int)(t*1000.0);
}
_glfwLibrary.Timer.t0_32 = _glfw_timeGetTime() - (int)(t * 1000.0);
}

File diff suppressed because it is too large Load Diff