Formatting pass (no code changes).

This commit is contained in:
Camilla Berglund 2010-09-08 15:51:25 +02:00
parent 8bc1a5da16
commit a04e041a6b
7 changed files with 769 additions and 790 deletions

View File

@ -39,11 +39,11 @@
// Enable system keys
//========================================================================
void _glfwPlatformEnableSystemKeys( void )
void _glfwPlatformEnableSystemKeys(void)
{
if( _glfwWin.keyboardGrabbed )
if (_glfwWin.keyboardGrabbed)
{
XUngrabKeyboard( _glfwLibrary.display, CurrentTime );
XUngrabKeyboard(_glfwLibrary.display, CurrentTime);
_glfwWin.keyboardGrabbed = GL_FALSE;
}
}
@ -52,11 +52,11 @@ void _glfwPlatformEnableSystemKeys( void )
// Disable system keys
//========================================================================
void _glfwPlatformDisableSystemKeys( void )
void _glfwPlatformDisableSystemKeys(void)
{
if( XGrabKeyboard( _glfwLibrary.display, _glfwWin.window, True,
GrabModeAsync, GrabModeAsync, CurrentTime ) ==
GrabSuccess )
if (XGrabKeyboard(_glfwLibrary.display, _glfwWin.window,
True, GrabModeAsync, GrabModeAsync, CurrentTime)
== GrabSuccess)
{
_glfwWin.keyboardGrabbed = GL_TRUE;
}

View File

@ -41,21 +41,21 @@
// 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;
// Special case: BPP = 32 (I don't think this is necessary for X11??)
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;
}
@ -64,9 +64,9 @@ static void BPP2RGB( int bpp, int *r, int *g, int *b )
// Finds the video mode closest in size to the specified desired size
//========================================================================
int _glfwGetClosestVideoMode( int screen, int *width, int *height, int *rate )
int _glfwGetClosestVideoMode(int screen, int *width, int *height, int *rate)
{
#if defined( _GLFW_HAS_XRANDR )
#if defined(_GLFW_HAS_XRANDR)
int i, match, bestmatch;
int sizecount, bestsize;
int ratecount, bestrate;
@ -74,107 +74,107 @@ int _glfwGetClosestVideoMode( int screen, int *width, int *height, int *rate )
XRRScreenConfiguration *sc;
XRRScreenSize *sizelist;
if( _glfwLibrary.XRandR.available )
if (_glfwLibrary.XRandR.available)
{
sc = XRRGetScreenInfo( _glfwLibrary.display,
RootWindow( _glfwLibrary.display, screen ) );
sc = XRRGetScreenInfo(_glfwLibrary.display,
RootWindow(_glfwLibrary.display, screen));
sizelist = XRRConfigSizes( sc, &sizecount );
sizelist = XRRConfigSizes(sc, &sizecount);
// Find the best matching mode
bestsize = -1;
bestmatch = INT_MAX;
for( i = 0; i < sizecount; i++ )
for (i = 0; i < sizecount; i++)
{
match = (*width - sizelist[i].width) *
(*width - sizelist[i].width) +
(*height - sizelist[i].height) *
(*height - sizelist[i].height);
if( match < bestmatch )
if (match < bestmatch)
{
bestmatch = match;
bestsize = i;
}
}
if( bestsize != -1 )
if (bestsize != -1)
{
// Report width & height of best matching mode
*width = sizelist[bestsize].width;
*height = sizelist[bestsize].height;
if( *rate > 0 )
if (*rate > 0)
{
ratelist = XRRConfigRates( sc, bestsize, &ratecount );
ratelist = XRRConfigRates(sc, bestsize, &ratecount);
bestrate = -1;
bestmatch = INT_MAX;
for( i = 0; i < ratecount; i++ )
for (i = 0; i < ratecount; i++)
{
match = abs( ratelist[i] - *rate );
if( match < bestmatch )
match = abs(ratelist[i] - *rate);
if (match < bestmatch)
{
bestmatch = match;
bestrate = ratelist[i];
}
}
if( bestrate != -1 )
if (bestrate != -1)
*rate = bestrate;
}
}
// Free modelist
XRRFreeScreenConfigInfo( sc );
XRRFreeScreenConfigInfo(sc);
if( bestsize != -1 )
if (bestsize != -1)
return bestsize;
}
#elif defined( _GLFW_HAS_XF86VIDMODE )
#elif defined(_GLFW_HAS_XF86VIDMODE)
XF86VidModeModeInfo **modelist;
int modecount, i, bestmode, bestmatch, match;
// Use the XF86VidMode extension to control video resolution
if( _glfwLibrary.XF86VidMode.available )
if (_glfwLibrary.XF86VidMode.available)
{
// Get a list of all available display modes
XF86VidModeGetAllModeLines( _glfwLibrary.display, screen,
&modecount, &modelist );
XF86VidModeGetAllModeLines(_glfwLibrary.display, screen,
&modecount, &modelist);
// Find the best matching mode
bestmode = -1;
bestmatch = INT_MAX;
for( i = 0; i < modecount; i++ )
for (i = 0; i < modecount; i++)
{
match = (*width - modelist[i]->hdisplay) *
(*width - modelist[i]->hdisplay) +
(*height - modelist[i]->vdisplay) *
(*height - modelist[i]->vdisplay);
if( match < bestmatch )
if (match < bestmatch)
{
bestmatch = match;
bestmode = i;
}
}
if( bestmode != -1 )
if (bestmode != -1)
{
// Report width & height of best matching mode
*width = modelist[ bestmode ]->hdisplay;
*height = modelist[ bestmode ]->vdisplay;
*width = modelist[bestmode]->hdisplay;
*height = modelist[bestmode]->vdisplay;
}
// Free modelist
XFree( modelist );
XFree(modelist);
if( bestmode != -1 )
if (bestmode != -1)
return bestmode;
}
#endif
// Default: Simply use the screen resolution
*width = DisplayWidth( _glfwLibrary.display, screen );
*height = DisplayHeight( _glfwLibrary.display, screen );
*width = DisplayWidth(_glfwLibrary.display, screen);
*height = DisplayHeight(_glfwLibrary.display, screen);
return 0;
}
@ -184,85 +184,85 @@ int _glfwGetClosestVideoMode( int screen, int *width, int *height, int *rate )
// Change the current video mode
//========================================================================
void _glfwSetVideoModeMODE( int screen, int mode, int rate )
void _glfwSetVideoModeMODE(int screen, int mode, int rate)
{
#if defined( _GLFW_HAS_XRANDR )
#if defined(_GLFW_HAS_XRANDR)
XRRScreenConfiguration *sc;
Window root;
if( _glfwLibrary.XRandR.available )
if (_glfwLibrary.XRandR.available)
{
root = RootWindow( _glfwLibrary.display, screen );
sc = XRRGetScreenInfo( _glfwLibrary.display, root );
root = RootWindow(_glfwLibrary.display, screen);
sc = XRRGetScreenInfo(_glfwLibrary.display, root);
// Remember old size and flag that we have changed the mode
if( !_glfwWin.FS.modeChanged )
if (!_glfwWin.FS.modeChanged)
{
_glfwWin.FS.oldSizeID = XRRConfigCurrentConfiguration( sc, &_glfwWin.FS.oldRotation );
_glfwWin.FS.oldWidth = DisplayWidth( _glfwLibrary.display, screen );
_glfwWin.FS.oldHeight = DisplayHeight( _glfwLibrary.display, screen );
_glfwWin.FS.oldSizeID = XRRConfigCurrentConfiguration(sc, &_glfwWin.FS.oldRotation);
_glfwWin.FS.oldWidth = DisplayWidth(_glfwLibrary.display, screen);
_glfwWin.FS.oldHeight = DisplayHeight(_glfwLibrary.display, screen);
_glfwWin.FS.modeChanged = GL_TRUE;
}
if( rate > 0 )
if (rate > 0)
{
// Set desired configuration
XRRSetScreenConfigAndRate( _glfwLibrary.display,
sc,
root,
mode,
RR_Rotate_0,
(short) rate,
CurrentTime );
XRRSetScreenConfigAndRate(_glfwLibrary.display,
sc,
root,
mode,
RR_Rotate_0,
(short) rate,
CurrentTime);
}
else
{
// Set desired configuration
XRRSetScreenConfig( _glfwLibrary.display,
sc,
root,
mode,
RR_Rotate_0,
CurrentTime );
XRRSetScreenConfig(_glfwLibrary.display,
sc,
root,
mode,
RR_Rotate_0,
CurrentTime);
}
XRRFreeScreenConfigInfo( sc );
XRRFreeScreenConfigInfo(sc);
}
#elif defined( _GLFW_HAS_XF86VIDMODE )
#elif defined(_GLFW_HAS_XF86VIDMODE)
XF86VidModeModeInfo **modelist;
int modecount;
// Use the XF86VidMode extension to control video resolution
if( _glfwLibrary.XF86VidMode.available )
if (_glfwLibrary.XF86VidMode.available)
{
// Get a list of all available display modes
XF86VidModeGetAllModeLines( _glfwLibrary.display, screen,
&modecount, &modelist );
XF86VidModeGetAllModeLines(_glfwLibrary.display, screen,
&modecount, &modelist);
// Unlock mode switch if necessary
if( _glfwWin.FS.modeChanged )
XF86VidModeLockModeSwitch( _glfwLibrary.display, screen, 0 );
if (_glfwWin.FS.modeChanged)
XF86VidModeLockModeSwitch(_glfwLibrary.display, screen, 0);
// Change the video mode to the desired mode
XF86VidModeSwitchToMode( _glfwLibrary.display, screen,
modelist[ mode ] );
XF86VidModeSwitchToMode(_glfwLibrary.display, screen,
modelist[mode]);
// Set viewport to upper left corner (where our window will be)
XF86VidModeSetViewPort( _glfwLibrary.display, screen, 0, 0 );
XF86VidModeSetViewPort(_glfwLibrary.display, screen, 0, 0);
// Lock mode switch
XF86VidModeLockModeSwitch( _glfwLibrary.display, screen, 1 );
XF86VidModeLockModeSwitch(_glfwLibrary.display, screen, 1);
// Remember old mode and flag that we have changed the mode
if( !_glfwWin.FS.modeChanged )
if (!_glfwWin.FS.modeChanged)
{
_glfwWin.FS.oldMode = *modelist[ 0 ];
_glfwWin.FS.oldMode = *modelist[0];
_glfwWin.FS.modeChanged = GL_TRUE;
}
// Free mode list
XFree( modelist );
XFree(modelist);
}
#endif
}
@ -272,15 +272,15 @@ void _glfwSetVideoModeMODE( int screen, int mode, int rate )
// Change the current video mode
//========================================================================
void _glfwSetVideoMode( int screen, int *width, int *height, int *rate )
void _glfwSetVideoMode(int screen, int *width, int *height, int *rate)
{
int bestmode;
// Find a best match mode
bestmode = _glfwGetClosestVideoMode( screen, width, height, rate );
bestmode = _glfwGetClosestVideoMode(screen, width, height, rate);
// Change mode
_glfwSetVideoModeMODE( screen, bestmode, *rate );
_glfwSetVideoModeMODE(screen, bestmode, *rate);
}
@ -288,39 +288,39 @@ void _glfwSetVideoMode( int screen, int *width, int *height, int *rate )
// Restore the previously saved (original) video mode
//========================================================================
void _glfwRestoreVideoMode( void )
void _glfwRestoreVideoMode(void)
{
if( _glfwWin.FS.modeChanged )
if (_glfwWin.FS.modeChanged)
{
#if defined( _GLFW_HAS_XRANDR )
if( _glfwLibrary.XRandR.available )
#if defined(_GLFW_HAS_XRANDR)
if (_glfwLibrary.XRandR.available)
{
XRRScreenConfiguration *sc;
if( _glfwLibrary.XRandR.available )
if (_glfwLibrary.XRandR.available)
{
sc = XRRGetScreenInfo( _glfwLibrary.display, _glfwWin.root );
sc = XRRGetScreenInfo(_glfwLibrary.display, _glfwWin.root);
XRRSetScreenConfig( _glfwLibrary.display,
sc,
_glfwWin.root,
_glfwWin.FS.oldSizeID,
_glfwWin.FS.oldRotation,
CurrentTime );
XRRSetScreenConfig(_glfwLibrary.display,
sc,
_glfwWin.root,
_glfwWin.FS.oldSizeID,
_glfwWin.FS.oldRotation,
CurrentTime);
XRRFreeScreenConfigInfo( sc );
XRRFreeScreenConfigInfo(sc);
}
}
#elif defined( _GLFW_HAS_XF86VIDMODE )
if( _glfwLibrary.XF86VidMode.available )
#elif defined(_GLFW_HAS_XF86VIDMODE)
if (_glfwLibrary.XF86VidMode.available)
{
// Unlock mode switch
XF86VidModeLockModeSwitch( _glfwLibrary.display, _glfwWin.screen, 0 );
XF86VidModeLockModeSwitch(_glfwLibrary.display, _glfwWin.screen, 0);
// Change the video mode back to the old mode
XF86VidModeSwitchToMode( _glfwLibrary.display,
XF86VidModeSwitchToMode(_glfwLibrary.display,
_glfwWin.screen,
&_glfwWin.FS.oldMode );
&_glfwWin.FS.oldMode);
}
#endif
_glfwWin.FS.modeChanged = GL_FALSE;
@ -343,7 +343,7 @@ struct _glfwResolution
// List available video modes
//========================================================================
int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )
int _glfwPlatformGetVideoModes(GLFWvidmode *list, int maxcount)
{
int count, k, l, r, g, b, rgba, gl;
int depth, screen;
@ -352,52 +352,52 @@ int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )
int viscount, rgbcount, rescount;
int *rgbarray;
struct _glfwResolution *resarray;
#if defined( _GLFW_HAS_XRANDR )
#if defined(_GLFW_HAS_XRANDR)
XRRScreenConfiguration *sc;
XRRScreenSize *sizelist;
int sizecount;
#elif defined( _GLFW_HAS_XF86VIDMODE )
#elif defined(_GLFW_HAS_XF86VIDMODE)
XF86VidModeModeInfo **modelist;
int modecount, width, height;
#endif
// Get display and screen
dpy = _glfwLibrary.display;
screen = DefaultScreen( dpy );
screen = DefaultScreen(dpy);
// Get list of visuals
vislist = XGetVisualInfo( dpy, 0, &dummy, &viscount );
if( vislist == NULL )
vislist = XGetVisualInfo(dpy, 0, &dummy, &viscount);
if (vislist == NULL)
return 0;
rgbarray = (int*) malloc( sizeof(int) * viscount );
rgbarray = (int*) malloc(sizeof(int) * viscount);
rgbcount = 0;
// Build RGB array
for( k = 0; k < viscount; k++ )
for (k = 0; k < viscount; k++)
{
// Does the visual support OpenGL & true color?
glXGetConfig( dpy, &vislist[k], GLX_USE_GL, &gl );
glXGetConfig( dpy, &vislist[k], GLX_RGBA, &rgba );
if( gl && rgba )
glXGetConfig(dpy, &vislist[k], GLX_USE_GL, &gl);
glXGetConfig(dpy, &vislist[k], GLX_RGBA, &rgba);
if (gl && rgba)
{
// Get color depth for this visual
depth = vislist[k].depth;
// Convert to RGB
BPP2RGB( depth, &r, &g, &b );
depth = (r<<16) | (g<<8) | b;
BPP2RGB(depth, &r, &g, &b);
depth = (r << 16) | (g << 8) | b;
// Is this mode unique?
for( l = 0; l < rgbcount; l++ )
for (l = 0; l < rgbcount; l++)
{
if( depth == rgbarray[ l ] )
if (depth == rgbarray[l])
break;
}
if( l >= rgbcount )
if (l >= rgbcount)
{
rgbarray[ rgbcount ] = depth;
rgbarray[rgbcount] = depth;
rgbcount++;
}
}
@ -407,83 +407,83 @@ int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )
resarray = NULL;
// Build resolution array
#if defined( _GLFW_HAS_XRANDR )
if( _glfwLibrary.XRandR.available )
#if defined(_GLFW_HAS_XRANDR)
if (_glfwLibrary.XRandR.available)
{
sc = XRRGetScreenInfo( dpy, RootWindow( dpy, screen ) );
sizelist = XRRConfigSizes( sc, &sizecount );
sc = XRRGetScreenInfo(dpy, RootWindow(dpy, screen));
sizelist = XRRConfigSizes(sc, &sizecount);
resarray = (struct _glfwResolution*) malloc( sizeof(struct _glfwResolution) * sizecount );
resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * sizecount);
for( k = 0; k < sizecount; k++ )
for (k = 0; k < sizecount; k++)
{
resarray[ rescount ].width = sizelist[ k ].width;
resarray[ rescount ].height = sizelist[ k ].height;
resarray[rescount].width = sizelist[k].width;
resarray[rescount].height = sizelist[k].height;
rescount++;
}
XRRFreeScreenConfigInfo( sc );
XRRFreeScreenConfigInfo(sc);
}
#elif defined( _GLFW_HAS_XF86VIDMODE )
if( _glfwLibrary.XF86VidMode.available )
#elif defined(_GLFW_HAS_XF86VIDMODE)
if (_glfwLibrary.XF86VidMode.available)
{
XF86VidModeGetAllModeLines( dpy, screen, &modecount, &modelist );
XF86VidModeGetAllModeLines(dpy, screen, &modecount, &modelist);
resarray = (struct _glfwResolution*) malloc( sizeof(struct _glfwResolution) * modecount );
resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * modecount);
for( k = 0; k < modecount; k++ )
for (k = 0; k < modecount; k++)
{
width = modelist[ k ]->hdisplay;
height = modelist[ k ]->vdisplay;
width = modelist[k]->hdisplay;
height = modelist[k]->vdisplay;
// Is this mode unique?
for( l = 0; l < rescount; l++ )
for (l = 0; l < rescount; l++)
{
if( width == resarray[ l ].width && height == resarray[ l ].height )
if (width == resarray[l].width && height == resarray[l].height)
break;
}
if( l >= rescount )
if (l >= rescount)
{
resarray[ rescount ].width = width;
resarray[ rescount ].height = height;
resarray[rescount].width = width;
resarray[rescount].height = height;
rescount++;
}
}
XFree( modelist );
XFree(modelist);
}
#endif
if( !resarray )
if (!resarray)
{
rescount = 1;
resarray = (struct _glfwResolution*) malloc( sizeof(struct _glfwResolution) * rescount );
resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * rescount);
resarray[ 0 ].width = DisplayWidth( dpy, screen );
resarray[ 0 ].height = DisplayHeight( dpy, screen );
resarray[ 0 ].width = DisplayWidth(dpy, screen);
resarray[ 0 ].height = DisplayHeight(dpy, screen);
}
// Build permutations of colors and resolutions
count = 0;
for( k = 0; k < rgbcount && count < maxcount; k++ )
for (k = 0; k < rgbcount && count < maxcount; k++)
{
for( l = 0; l < rescount && count < maxcount; l++ )
for (l = 0; l < rescount && count < maxcount; l++)
{
list[count].Width = resarray[ l ].width;
list[count].Height = resarray[ l ].height;
list[count].RedBits = (rgbarray[ k ] >> 16) & 255;
list[count].GreenBits = (rgbarray[ k ] >> 8) & 255;
list[count].BlueBits = rgbarray[ k ] & 255;
list[count].Width = resarray[l].width;
list[count].Height = resarray[l].height;
list[count].RedBits = (rgbarray[k] >> 16) & 255;
list[count].GreenBits = (rgbarray[k] >> 8) & 255;
list[count].BlueBits = rgbarray[k] & 255;
count++;
}
}
// Free visuals list
XFree( vislist );
XFree(vislist);
free( resarray );
free( rgbarray );
free(resarray);
free(rgbarray);
return count;
}
@ -493,39 +493,39 @@ int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )
// Get the desktop video mode
//========================================================================
void _glfwPlatformGetDesktopMode( GLFWvidmode *mode )
void _glfwPlatformGetDesktopMode(GLFWvidmode *mode)
{
Display *dpy;
int bpp, screen;
#if defined( _GLFW_HAS_XF86VIDMODE )
int bpp, screen;
#if defined(_GLFW_HAS_XF86VIDMODE)
XF86VidModeModeInfo **modelist;
int modecount;
int modecount;
#endif
// Get display and screen
dpy = _glfwLibrary.display;
screen = DefaultScreen( dpy );
screen = DefaultScreen(dpy);
// Get display depth
bpp = DefaultDepth( dpy, screen );
bpp = DefaultDepth(dpy, screen);
// Convert BPP to RGB bits
BPP2RGB( bpp, &mode->RedBits, &mode->GreenBits, &mode->BlueBits );
BPP2RGB(bpp, &mode->RedBits, &mode->GreenBits, &mode->BlueBits);
#if defined( _GLFW_HAS_XRANDR )
if( _glfwLibrary.XRandR.available )
#if defined(_GLFW_HAS_XRANDR)
if (_glfwLibrary.XRandR.available)
{
if( _glfwWin.FS.modeChanged )
if (_glfwWin.FS.modeChanged)
{
mode->Width = _glfwWin.FS.oldWidth;
mode->Height = _glfwWin.FS.oldHeight;
return;
}
}
#elif defined( _GLFW_HAS_XF86VIDMODE )
if( _glfwLibrary.XF86VidMode.available )
#elif defined(_GLFW_HAS_XF86VIDMODE)
if (_glfwLibrary.XF86VidMode.available)
{
if( _glfwWin.FS.modeChanged )
if (_glfwWin.FS.modeChanged)
{
// The old (desktop) mode is stored in _glfwWin.FS.oldMode
mode->Width = _glfwWin.FS.oldMode.hdisplay;
@ -534,15 +534,14 @@ void _glfwPlatformGetDesktopMode( GLFWvidmode *mode )
else
{
// Use the XF86VidMode extension to get list of video modes
XF86VidModeGetAllModeLines( dpy, screen, &modecount,
&modelist );
XF86VidModeGetAllModeLines(dpy, screen, &modecount, &modelist);
// The first mode in the list is the current (desktio) mode
mode->Width = modelist[ 0 ]->hdisplay;
mode->Height = modelist[ 0 ]->vdisplay;
mode->Width = modelist[0]->hdisplay;
mode->Height = modelist[0]->vdisplay;
// Free list
XFree( modelist );
XFree(modelist);
}
return;
@ -550,7 +549,7 @@ void _glfwPlatformGetDesktopMode( GLFWvidmode *mode )
#endif
// Get current display width and height
mode->Width = DisplayWidth( dpy, screen );
mode->Height = DisplayHeight( dpy, screen );
mode->Width = DisplayWidth(dpy, screen);
mode->Height = DisplayHeight(dpy, screen);
}

View File

@ -38,13 +38,13 @@ void (*glXGetProcAddressEXT(const GLubyte *procName))();
// We support four different ways for getting addresses for GL/GLX
// extension functions: glXGetProcAddress, glXGetProcAddressARB,
// glXGetProcAddressEXT, and dlsym
#if defined( _GLFW_HAS_GLXGETPROCADDRESSARB )
#if defined(_GLFW_HAS_GLXGETPROCADDRESSARB)
#define _glfw_glXGetProcAddress(x) glXGetProcAddressARB(x)
#elif defined( _GLFW_HAS_GLXGETPROCADDRESS )
#elif defined(_GLFW_HAS_GLXGETPROCADDRESS)
#define _glfw_glXGetProcAddress(x) glXGetProcAddress(x)
#elif defined( _GLFW_HAS_GLXGETPROCADDRESSEXT )
#elif defined(_GLFW_HAS_GLXGETPROCADDRESSEXT)
#define _glfw_glXGetProcAddress(x) glXGetProcAddressEXT(x)
#elif defined( _GLFW_HAS_DLOPEN )
#elif defined(_GLFW_HAS_DLOPEN)
#define _glfw_glXGetProcAddress(x) dlsym(_glfwLibs.libGL,x)
#define _GLFW_DLOPEN_LIBGL
#else
@ -60,16 +60,16 @@ void (*glXGetProcAddressEXT(const GLubyte *procName))();
// Check if an OpenGL extension is available at runtime
//========================================================================
int _glfwPlatformExtensionSupported( const char *extension )
int _glfwPlatformExtensionSupported(const char *extension)
{
const GLubyte *extensions;
// Get list of GLX extensions
extensions = (const GLubyte*) glXQueryExtensionsString( _glfwLibrary.display,
_glfwWin.screen );
if( extensions != NULL )
extensions = (const GLubyte*) glXQueryExtensionsString(_glfwLibrary.display,
_glfwWin.screen);
if (extensions != NULL)
{
if( _glfwStringInExtensionString( extension, extensions ) )
if (_glfwStringInExtensionString(extension, extensions))
return GL_TRUE;
}
@ -81,8 +81,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 *) _glfw_glXGetProcAddress( (const GLubyte *) procname );
return (void *) _glfw_glXGetProcAddress((const GLubyte *) procname);
}

View File

@ -39,7 +39,7 @@
// Dynamically load libraries
//========================================================================
static void initLibraries( void )
static void initLibraries(void)
{
#ifdef _GLFW_DLOPEN_LIBGL
int i;
@ -53,11 +53,10 @@ static void initLibraries( void )
};
_glfwLibrary.Libs.libGL = NULL;
for( i = 0; !libGL_names[ i ] != NULL; i ++ )
for (i = 0; libGL_names[i] != NULL; i++)
{
_glfwLibrary.Libs.libGL = dlopen( libGL_names[ i ],
RTLD_LAZY | RTLD_GLOBAL );
if( _glfwLibrary.Libs.libGL )
_glfwLibrary.Libs.libGL = dlopen(libGL_names[i], RTLD_LAZY | RTLD_GLOBAL);
if (_glfwLibrary.Libs.libGL)
break;
}
#endif
@ -68,7 +67,7 @@ static void initLibraries( void )
// Terminate GLFW when exiting application
//========================================================================
static void glfw_atexit( void )
static void glfw_atexit(void)
{
glfwTerminate();
}
@ -78,11 +77,11 @@ static void glfw_atexit( void )
// Initialize X11 display
//========================================================================
static int initDisplay( void )
static int initDisplay(void)
{
// Open display
_glfwLibrary.display = XOpenDisplay( 0 );
if( !_glfwLibrary.display )
_glfwLibrary.display = XOpenDisplay(0);
if (!_glfwLibrary.display)
{
fprintf(stderr, "Failed to open X display\n");
return GL_FALSE;
@ -91,9 +90,9 @@ static int initDisplay( void )
// Check for XF86VidMode extension
#ifdef _GLFW_HAS_XF86VIDMODE
_glfwLibrary.XF86VidMode.available =
XF86VidModeQueryExtension( _glfwLibrary.display,
&_glfwLibrary.XF86VidMode.eventBase,
&_glfwLibrary.XF86VidMode.errorBase);
XF86VidModeQueryExtension(_glfwLibrary.display,
&_glfwLibrary.XF86VidMode.eventBase,
&_glfwLibrary.XF86VidMode.errorBase);
#else
_glfwLibrary.XF86VidMode.available = 0;
#endif
@ -101,25 +100,25 @@ static int initDisplay( void )
// Check for XRandR extension
#ifdef _GLFW_HAS_XRANDR
_glfwLibrary.XRandR.available =
XRRQueryExtension( _glfwLibrary.display,
&_glfwLibrary.XRandR.eventBase,
&_glfwLibrary.XRandR.errorBase );
XRRQueryExtension(_glfwLibrary.display,
&_glfwLibrary.XRandR.eventBase,
&_glfwLibrary.XRandR.errorBase);
#else
_glfwLibrary.XRandR.available = 0;
#endif
// Fullscreen & screen saver settings
// Check if GLX is supported on this display
if( !glXQueryExtension( _glfwLibrary.display, NULL, NULL ) )
if (!glXQueryExtension(_glfwLibrary.display, NULL, NULL))
{
fprintf(stderr, "GLX not supported\n");
return GL_FALSE;
}
// Retrieve GLX version
if( !glXQueryVersion( _glfwLibrary.display,
&_glfwLibrary.glxMajor,
&_glfwLibrary.glxMinor ) )
if (!glXQueryVersion(_glfwLibrary.display,
&_glfwLibrary.glxMajor,
&_glfwLibrary.glxMinor))
{
fprintf(stderr, "Unable to query GLX version\n");
return GL_FALSE;
@ -133,12 +132,12 @@ static int initDisplay( void )
// Terminate X11 display
//========================================================================
static void terminateDisplay( void )
static void terminateDisplay(void)
{
// Open display
if( _glfwLibrary.display )
if (_glfwLibrary.display)
{
XCloseDisplay( _glfwLibrary.display );
XCloseDisplay(_glfwLibrary.display);
_glfwLibrary.display = NULL;
}
}
@ -152,16 +151,16 @@ static void terminateDisplay( void )
// Initialize various GLFW state
//========================================================================
int _glfwPlatformInit( void )
int _glfwPlatformInit(void)
{
if( !initDisplay() )
if (!initDisplay())
return GL_FALSE;
// Try to load libGL.so if necessary
initLibraries();
// Install atexit() routine
atexit( glfw_atexit );
atexit(glfw_atexit);
// Initialize joysticks
_glfwInitJoysticks();
@ -177,7 +176,7 @@ int _glfwPlatformInit( void )
// Close window and shut down library
//========================================================================
int _glfwPlatformTerminate( void )
int _glfwPlatformTerminate(void)
{
// Close OpenGL window
glfwCloseWindow();
@ -190,9 +189,9 @@ int _glfwPlatformTerminate( void )
// Unload libGL.so if necessary
#ifdef _GLFW_DLOPEN_LIBGL
if( _glfwLibrary.Libs.libGL != NULL )
if (_glfwLibrary.Libs.libGL != NULL)
{
dlclose( _glfwLibrary.Libs.libGL );
dlclose(_glfwLibrary.Libs.libGL);
_glfwLibrary.Libs.libGL = NULL;
}
#endif

View File

@ -77,28 +77,28 @@ struct js_event {
// Initialize joystick interface
//========================================================================
void _glfwInitJoysticks( void )
void _glfwInitJoysticks(void)
{
#ifdef _GLFW_USE_LINUX_JOYSTICKS
int k, n, fd, joy_count;
char *joy_base_name, joy_dev_name[ 20 ];
char *joy_base_name, joy_dev_name[20];
int driver_version = 0x000800;
char ret_data;
#endif // _GLFW_USE_LINUX_JOYSTICKS
int i;
// Start by saying that there are no sticks
for( i = 0; i <= GLFW_JOYSTICK_LAST; ++ i )
_glfwJoy[ i ].Present = GL_FALSE;
for (i = 0; i <= GLFW_JOYSTICK_LAST; i++)
_glfwJoy[i].Present = GL_FALSE;
#ifdef _GLFW_USE_LINUX_JOYSTICKS
// Try to open joysticks (nonblocking)
joy_count = 0;
for( k = 0; k <= 1 && joy_count <= GLFW_JOYSTICK_LAST; ++ k )
for (k = 0; k <= 1 && joy_count <= GLFW_JOYSTICK_LAST; k++)
{
// Pick joystick base name
switch( k )
switch (k)
{
case 0:
joy_base_name = "/dev/input/js"; // USB sticks
@ -111,67 +111,65 @@ void _glfwInitJoysticks( void )
}
// Try to open a few of these sticks
for( i = 0; i <= 50 && joy_count <= GLFW_JOYSTICK_LAST; ++ i )
for (i = 0; i <= 50 && joy_count <= GLFW_JOYSTICK_LAST; i++)
{
sprintf( joy_dev_name, "%s%d", joy_base_name, i );
fd = open( joy_dev_name, O_NONBLOCK );
if( fd != -1 )
sprintf(joy_dev_name, "%s%d", joy_base_name, i);
fd = open(joy_dev_name, O_NONBLOCK);
if (fd != -1)
{
// Remember fd
_glfwJoy[ joy_count ].fd = fd;
_glfwJoy[joy_count].fd = fd;
// Check that the joystick driver version is 1.0+
ioctl( fd, JSIOCGVERSION, &driver_version );
if( driver_version < 0x010000 )
ioctl(fd, JSIOCGVERSION, &driver_version);
if (driver_version < 0x010000)
{
// It's an old 0.x interface (we don't support it)
close( fd );
close(fd);
continue;
}
// Get number of joystick axes
ioctl( fd, JSIOCGAXES, &ret_data );
_glfwJoy[ joy_count ].NumAxes = (int) ret_data;
ioctl(fd, JSIOCGAXES, &ret_data);
_glfwJoy[joy_count].NumAxes = (int) ret_data;
// Get number of joystick buttons
ioctl( fd, JSIOCGBUTTONS, &ret_data );
_glfwJoy[ joy_count ].NumButtons = (int) ret_data;
ioctl(fd, JSIOCGBUTTONS, &ret_data);
_glfwJoy[joy_count].NumButtons = (int) ret_data;
// Allocate memory for joystick state
_glfwJoy[ joy_count ].Axis =
(float *) malloc( sizeof(float) *
_glfwJoy[ joy_count ].NumAxes );
if( _glfwJoy[ joy_count ].Axis == NULL )
_glfwJoy[joy_count].Axis =
(float *) malloc(sizeof(float) *
_glfwJoy[joy_count].NumAxes);
if (_glfwJoy[joy_count].Axis == NULL)
{
close( fd );
close(fd);
continue;
}
_glfwJoy[ joy_count ].Button =
(unsigned char *) malloc( sizeof(char) *
_glfwJoy[ joy_count ].NumButtons );
if( _glfwJoy[ joy_count ].Button == NULL )
_glfwJoy[joy_count].Button =
(unsigned char *) malloc(sizeof(char) *
_glfwJoy[joy_count].NumButtons);
if (_glfwJoy[joy_count].Button == NULL)
{
free( _glfwJoy[ joy_count ].Axis );
close( fd );
free(_glfwJoy[joy_count].Axis);
close(fd);
continue;
}
// Clear joystick state
for( n = 0; n < _glfwJoy[ joy_count ].NumAxes; ++ n )
_glfwJoy[ joy_count ].Axis[ n ] = 0.0f;
for (n = 0; n < _glfwJoy[joy_count].NumAxes; n++)
_glfwJoy[joy_count].Axis[n] = 0.0f;
for( n = 0; n < _glfwJoy[ joy_count ].NumButtons; ++ n )
_glfwJoy[ joy_count ].Button[ n ] = GLFW_RELEASE;
for (n = 0; n < _glfwJoy[joy_count].NumButtons; n++)
_glfwJoy[joy_count].Button[n] = GLFW_RELEASE;
// The joystick is supported and connected
_glfwJoy[ joy_count ].Present = GL_TRUE;
joy_count ++;
_glfwJoy[joy_count].Present = GL_TRUE;
joy_count++;
}
}
}
#endif // _GLFW_USE_LINUX_JOYSTICKS
}
@ -179,7 +177,7 @@ void _glfwInitJoysticks( void )
// Close all opened joystick handles
//========================================================================
void _glfwTerminateJoysticks( void )
void _glfwTerminateJoysticks(void)
{
#ifdef _GLFW_USE_LINUX_JOYSTICKS
@ -187,14 +185,15 @@ void _glfwTerminateJoysticks( void )
int i;
// Close any opened joysticks
for( i = 0; i <= GLFW_JOYSTICK_LAST; ++ i )
for (i = 0; i <= GLFW_JOYSTICK_LAST; i++)
{
if( _glfwJoy[ i ].Present )
if (_glfwJoy[i].Present)
{
close( _glfwJoy[ i ].fd );
free( _glfwJoy[ i ].Axis );
free( _glfwJoy[ i ].Button );
_glfwJoy[ i ].Present = GL_FALSE;
close(_glfwJoy[i].fd);
free(_glfwJoy[i].Axis);
free(_glfwJoy[i].Button);
_glfwJoy[i].Present = GL_FALSE;
}
}
@ -207,43 +206,38 @@ void _glfwTerminateJoysticks( void )
// Empty joystick event queue
//========================================================================
static void pollJoystickEvents( void )
static void pollJoystickEvents(void)
{
#ifdef _GLFW_USE_LINUX_JOYSTICKS
struct js_event e;
int i;
// Get joystick events for all GLFW joysticks
for( i = 0; i <= GLFW_JOYSTICK_LAST; ++ i )
for (i = 0; i <= GLFW_JOYSTICK_LAST; i++)
{
// Is the stick present?
if( _glfwJoy[ i ].Present )
if (_glfwJoy[i].Present)
{
// Read all queued events (non-blocking)
while( read(_glfwJoy[i].fd, &e, sizeof(struct js_event)) > 0 )
while (read(_glfwJoy[i].fd, &e, sizeof(struct js_event)) > 0)
{
// We don't care if it's an init event or not
e.type &= ~JS_EVENT_INIT;
// Check event type
switch( e.type )
switch (e.type)
{
case JS_EVENT_AXIS:
_glfwJoy[ i ].Axis[ e.number ] = (float) e.value /
32767.0f;
_glfwJoy[i].Axis[e.number] = (float) e.value / 32767.0f;
// We need to change the sign for the Y axes, so that
// positive = up/forward, according to the GLFW spec.
if( e.number & 1 )
{
_glfwJoy[ i ].Axis[ e.number ] =
-_glfwJoy[ i ].Axis[ e.number ];
}
if (e.number & 1)
_glfwJoy[i].Axis[e.number] = -_glfwJoy[i].Axis[e.number];
break;
case JS_EVENT_BUTTON:
_glfwJoy[ i ].Button[ e.number ] =
_glfwJoy[i].Button[e.number] =
e.value ? GLFW_PRESS : GLFW_RELEASE;
break;
@ -253,9 +247,7 @@ static void pollJoystickEvents( void )
}
}
}
#endif // _GLFW_USE_LINUX_JOYSTICKS
}
@ -267,21 +259,21 @@ static void pollJoystickEvents( void )
// Determine joystick capabilities
//========================================================================
int _glfwPlatformGetJoystickParam( int joy, int param )
int _glfwPlatformGetJoystickParam(int joy, int param)
{
if( !_glfwJoy[ joy ].Present )
if (!_glfwJoy[joy].Present)
return 0;
switch( param )
switch (param)
{
case GLFW_PRESENT:
return GL_TRUE;
case GLFW_AXES:
return _glfwJoy[ joy ].NumAxes;
return _glfwJoy[joy].NumAxes;
case GLFW_BUTTONS:
return _glfwJoy[ joy ].NumButtons;
return _glfwJoy[joy].NumButtons;
default:
break;
@ -295,23 +287,23 @@ 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)
{
int i;
if( !_glfwJoy[ joy ].Present )
if (!_glfwJoy[joy].Present)
return 0;
// Update joystick state
pollJoystickEvents();
// Does the joystick support less axes than requested?
if( _glfwJoy[ joy ].NumAxes < numaxes )
numaxes = _glfwJoy[ joy ].NumAxes;
if (_glfwJoy[joy].NumAxes < numaxes)
numaxes = _glfwJoy[joy].NumAxes;
// Copy axis positions from internal state
for( i = 0; i < numaxes; ++ i )
pos[ i ] = _glfwJoy[ joy ].Axis[ i ];
for (i = 0; i < numaxes; i++)
pos[i] = _glfwJoy[joy].Axis[i];
return numaxes;
}
@ -321,24 +313,24 @@ 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)
{
int i;
if( !_glfwJoy[ joy ].Present )
if (!_glfwJoy[joy].Present)
return 0;
// Update joystick state
pollJoystickEvents();
// Does the joystick support less buttons than requested?
if( _glfwJoy[ joy ].NumButtons < numbuttons )
numbuttons = _glfwJoy[ joy ].NumButtons;
if (_glfwJoy[joy].NumButtons < numbuttons)
numbuttons = _glfwJoy[joy].NumButtons;
// Copy button states from internal state
for( i = 0; i < numbuttons; ++ i )
buttons[ i ] = _glfwJoy[ joy ].Button[ i ];
for (i = 0; i < numbuttons; i++)
buttons[i] = _glfwJoy[joy].Button[i];
return numbuttons;
}

View File

@ -35,15 +35,15 @@
// Initialise timer
//========================================================================
void _glfwInitTimer( void )
void _glfwInitTimer(void)
{
struct timeval tv;
struct timeval tv;
// "Resolution" is 1 us
_glfwLibrary.Timer.resolution = 1e-6;
// Set start-time for timer
gettimeofday( &tv, NULL );
gettimeofday(&tv, NULL);
_glfwLibrary.Timer.t0 = (long long) tv.tv_sec * (long long) 1000000 +
(long long) tv.tv_usec;
}
@ -57,12 +57,12 @@ void _glfwInitTimer( void )
// Return timer value in seconds
//========================================================================
double _glfwPlatformGetTime( void )
double _glfwPlatformGetTime(void)
{
long long t;
struct timeval tv;
struct timeval tv;
gettimeofday( &tv, NULL );
gettimeofday(&tv, NULL);
t = (long long) tv.tv_sec * (long long) 1000000 +
(long long) tv.tv_usec;
@ -74,16 +74,16 @@ double _glfwPlatformGetTime( void )
// Set timer value in seconds
//========================================================================
void _glfwPlatformSetTime( double t )
void _glfwPlatformSetTime(double t)
{
long long t0;
struct timeval tv;
gettimeofday( &tv, NULL );
gettimeofday(&tv, NULL);
t0 = (long long) tv.tv_sec * (long long) 1000000 +
(long long) tv.tv_usec;
// Calulate new starting time
_glfwLibrary.Timer.t0 = t0 - (long long)(t/_glfwLibrary.Timer.resolution);
_glfwLibrary.Timer.t0 = t0 - (long long)(t / _glfwLibrary.Timer.resolution);
}

File diff suppressed because it is too large Load Diff