X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffreeglut_state.c;h=9b31f15da328b4debbbb3c0319d5782c4ebe97d9;hb=dceb9a06b643633134bd70ed7b7c281250f9cb3f;hp=f628c7ee1b1a7efc3aca6deaca52146427724c5b;hpb=6fadb32a79a194e7d09a553d425c7e2e26db258b;p=freeglut diff --git a/src/freeglut_state.c b/src/freeglut_state.c index f628c7e..9b31f15 100644 --- a/src/freeglut_state.c +++ b/src/freeglut_state.c @@ -37,8 +37,10 @@ /* * TODO BEFORE THE STABLE RELEASE: * - * glutGet() -- X11 tests passed, but check if all enums handled (what about Win32?) - * glutDeviceGet() -- X11 tests passed, but check if all enums handled (what about Win32?) + * glutGet() -- X11 tests passed, but check if all enums + * handled (what about Win32?) + * glutDeviceGet() -- X11 tests passed, but check if all enums + * handled (what about Win32?) * glutGetModifiers() -- OK, but could also remove the limitation * glutLayerGet() -- what about GLUT_NORMAL_DAMAGED? * @@ -55,24 +57,13 @@ */ static int fghGetConfig( int attribute ) { - int returnValue ; - - /* - * Return nothing if there is no current window set - */ - if( fgStructure.Window == NULL ) - return( 0 ); + int returnValue = 0; - /* - * glXGetConfig should work fine - */ - glXGetConfig( fgDisplay.Display, fgStructure.Window->Window.VisualInfo, attribute, &returnValue ); + if( fgStructure.Window ) + glXGetConfig( fgDisplay.Display, fgStructure.Window->Window.VisualInfo, + attribute, &returnValue ); - - /* - * Have the query results returned - */ - return ( returnValue ) ; + return returnValue; } #endif @@ -90,26 +81,39 @@ void FGAPIENTRY glutSetOption( GLenum eWhat, int value ) */ switch( eWhat ) { - case GLUT_INIT_WINDOW_X: fgState.Position.X = (GLint)value ; - break ; - case GLUT_INIT_WINDOW_Y: fgState.Position.Y = (GLint)value ; - break ; - case GLUT_INIT_WINDOW_WIDTH: fgState.Size.X = (GLint)value ; - break ; - case GLUT_INIT_WINDOW_HEIGHT: fgState.Size.Y = (GLint)value ; - break ; - case GLUT_INIT_DISPLAY_MODE: fgState.DisplayMode = (unsigned int)value ; - break ; - - case GLUT_ACTION_ON_WINDOW_CLOSE: fgState.ActionOnWindowClose = value ; - break ; - - case GLUT_RENDERING_CONTEXT: fgState.UseCurrentContext = ( value == GLUT_USE_CURRENT_CONTEXT ) ? TRUE : FALSE ; - break ; + case GLUT_INIT_WINDOW_X: + fgState.Position.X = (GLint)value; + break; + + case GLUT_INIT_WINDOW_Y: + fgState.Position.Y = (GLint)value; + break; + + case GLUT_INIT_WINDOW_WIDTH: + fgState.Size.X = (GLint)value; + break; + + case GLUT_INIT_WINDOW_HEIGHT: + fgState.Size.Y = (GLint)value; + break; + + case GLUT_INIT_DISPLAY_MODE: + fgState.DisplayMode = (unsigned int)value; + break; + + case GLUT_ACTION_ON_WINDOW_CLOSE: + fgState.ActionOnWindowClose = value; + break; + + case GLUT_RENDERING_CONTEXT: + fgState.UseCurrentContext = + ( value == GLUT_USE_CURRENT_CONTEXT ) ? TRUE : FALSE; + break; case GLUT_WINDOW_CURSOR: - if( fgStructure.Window != NULL ) fgStructure.Window->State.Cursor = value ; - break ; + if( fgStructure.Window != NULL ) + fgStructure.Window->State.Cursor = value; + break; default: /* @@ -215,6 +219,8 @@ int FGAPIENTRY glutGet( GLenum eWhat ) */ case GLUT_WINDOW_X: case GLUT_WINDOW_Y: + case GLUT_WINDOW_BORDER_WIDTH: + case GLUT_WINDOW_HEADER_HEIGHT: { int x, y; Window w; @@ -233,12 +239,24 @@ int FGAPIENTRY glutGet( GLenum eWhat ) case GLUT_WINDOW_X: return x; case GLUT_WINDOW_Y: return y; } + + if ( w == 0 ) + return( 0 ); /* Just in case */ + + XTranslateCoordinates( + fgDisplay.Display, + fgStructure.Window->Window.Handle, + w, 0, 0, &x, &y, &w); + + switch ( eWhat ) + { + case GLUT_WINDOW_BORDER_WIDTH: return x; + case GLUT_WINDOW_HEADER_HEIGHT: return y; + } } case GLUT_WINDOW_WIDTH: case GLUT_WINDOW_HEIGHT: - case GLUT_WINDOW_BORDER_WIDTH : - case GLUT_WINDOW_HEADER_HEIGHT : { XWindowAttributes winAttributes; @@ -264,8 +282,6 @@ int FGAPIENTRY glutGet( GLenum eWhat ) { case GLUT_WINDOW_WIDTH: return winAttributes.width ; case GLUT_WINDOW_HEIGHT: return winAttributes.height ; - case GLUT_WINDOW_BORDER_WIDTH : return winAttributes.border_width ; - case GLUT_WINDOW_HEADER_HEIGHT : return winAttributes.border_width * 3 ; /* a kludge for now */ } } @@ -296,44 +312,44 @@ int FGAPIENTRY glutGet( GLenum eWhat ) * Handle the OpenGL inquiries */ case GLUT_WINDOW_RGBA: - glGetBooleanv ( GL_RGBA_MODE, &boolValue ) ; /* True if color buffers store RGBA */ + glGetBooleanv ( GL_RGBA_MODE, &boolValue ) ; returnValue = boolValue ? 1 : 0 ; return ( returnValue ) ; case GLUT_WINDOW_DOUBLEBUFFER: - glGetBooleanv ( GL_DOUBLEBUFFER, &boolValue ) ; /* True if front and back buffers exist */ + glGetBooleanv ( GL_DOUBLEBUFFER, &boolValue ) ; returnValue = boolValue ? 1 : 0 ; return ( returnValue ) ; case GLUT_WINDOW_STEREO: - glGetBooleanv ( GL_STEREO, &boolValue ) ; /* True if left and right buffers exist */ + glGetBooleanv ( GL_STEREO, &boolValue ) ; returnValue = boolValue ? 1 : 0 ; return ( returnValue ) ; case GLUT_WINDOW_RED_SIZE: - glGetIntegerv ( GL_RED_BITS, &returnValue ) ; /* Number of bits per red component in color buffers */ + glGetIntegerv ( GL_RED_BITS, &returnValue ) ; return ( returnValue ) ; case GLUT_WINDOW_GREEN_SIZE: - glGetIntegerv ( GL_GREEN_BITS, &returnValue ) ; /* Number of bits per green component in color buffers */ + glGetIntegerv ( GL_GREEN_BITS, &returnValue ) ; return ( returnValue ) ; case GLUT_WINDOW_BLUE_SIZE: - glGetIntegerv ( GL_BLUE_BITS, &returnValue ) ; /* Number of bits per blue component in color buffers */ + glGetIntegerv ( GL_BLUE_BITS, &returnValue ) ; return ( returnValue ) ; case GLUT_WINDOW_ALPHA_SIZE: - glGetIntegerv ( GL_ALPHA_BITS, &returnValue ) ; /* Number of bits per alpha component in color buffers */ + glGetIntegerv ( GL_ALPHA_BITS, &returnValue ) ; return ( returnValue ) ; case GLUT_WINDOW_ACCUM_RED_SIZE: - glGetIntegerv ( GL_ACCUM_RED_BITS, &returnValue ) ; /* Number of bits per red component in the accumulation buffer */ + glGetIntegerv ( GL_ACCUM_RED_BITS, &returnValue ) ; return ( returnValue ) ; case GLUT_WINDOW_ACCUM_GREEN_SIZE: - glGetIntegerv ( GL_ACCUM_GREEN_BITS, &returnValue ) ; /* Number of bits per green component in the accumulation buffer */ + glGetIntegerv ( GL_ACCUM_GREEN_BITS, &returnValue ) ; return ( returnValue ) ; case GLUT_WINDOW_ACCUM_BLUE_SIZE: - glGetIntegerv ( GL_ACCUM_BLUE_BITS, &returnValue ) ; /* Number of bits per blue component in the accumulation buffer */ + glGetIntegerv ( GL_ACCUM_BLUE_BITS, &returnValue ) ; return ( returnValue ) ; case GLUT_WINDOW_ACCUM_ALPHA_SIZE: - glGetIntegerv ( GL_ACCUM_ALPHA_BITS, &returnValue ) ; /* Number of bits per alpha component in the accumulation buffer */ + glGetIntegerv ( GL_ACCUM_ALPHA_BITS, &returnValue ) ; return ( returnValue ) ; case GLUT_WINDOW_DEPTH_SIZE: - glGetIntegerv ( GL_DEPTH_BITS, &returnValue ) ; /* Number of depth-buffer bitplanes */ + glGetIntegerv ( GL_DEPTH_BITS, &returnValue ) ; return ( returnValue ) ; case GLUT_WINDOW_BUFFER_SIZE: @@ -352,28 +368,31 @@ int FGAPIENTRY glutGet( GLenum eWhat ) case GLUT_WINDOW_HEIGHT: { /* - * There is considerable confusion about the "right thing to do" concerning window - * size and position. GLUT itself is not consistent between Windows and Linux; since - * platform independence is a virtue for "freeglut", we decided to break with GLUT's - * behaviour. - * Under Linux, it is apparently not possible to get the window border sizes in order - * to subtract them off the window's initial position until some time after the window - * has been created. Therefore we decided on the following behaviour, both under - * Windows and under Linux: - * - When you create a window with position (x,y) and size (w,h), the upper left hand - * corner of the outside of the window is at (x,y) and the size of the drawable area - * is (w,h). - * - When you query the size and position of the window--as is happening here for - * Windows--"freeglut" will return the size of the drawable area--the (w,h) that you - * specified when you created the window--and the coordinates of the upper left hand - * corner of the drawable area--which is NOT the (x,y) you specified. + * There is considerable confusion about the "right thing to + * do" concerning window size and position. GLUT itself is + * not consistent between Windows and UNIX/X11; since + * platform independence is a virtue for "freeglut", we + * decided to break with GLUT's behaviour. + * + * Under UNIX/X11, it is apparently not possible to get the + * window border sizes in order to subtract them off the + * window's initial position until some time after the window + * has been created. Therefore we decided on the following + * behaviour, both under Windows and under UNIX/X11: + * - When you create a window with position (x,y) and size + * (w,h), the upper left hand corner of the outside of the + * window is at (x,y) and the size of the drawable area is + * (w,h). + * - When you query the size and position of the window--as + * is happening here for Windows--"freeglut" will return + * the size of the drawable area--the (w,h) that you + * specified when you created the window--and the coordinates + * of the upper left hand corner of the drawable + * area--which is NOT the (x,y) you specified. */ RECT winRect; - /* - * Check if there is a window to be queried for dimensions: - */ freeglut_return_val_if_fail( fgStructure.Window != NULL, 0 ); /* @@ -394,9 +413,6 @@ int FGAPIENTRY glutGet( GLenum eWhat ) winRect.bottom -= GetSystemMetrics( SM_CYSIZEFRAME ); } - /* - * ...and finally return the caller the desired value: - */ switch( eWhat ) { case GLUT_WINDOW_X: return( winRect.left ); @@ -414,15 +430,9 @@ int FGAPIENTRY glutGet( GLenum eWhat ) return ( GetSystemMetrics( SM_CYCAPTION ) ) ; case GLUT_DISPLAY_MODE_POSSIBLE: - /* - * Check if the current display mode is possible - */ return( fgSetupPixelFormat( fgStructure.Window, TRUE, PFD_MAIN_PLANE ) ); case GLUT_WINDOW_FORMAT_ID: - /* - * Return the pixel format of the current window - */ if( fgStructure.Window != NULL ) return( GetPixelFormat( fgStructure.Window->Window.Device ) );