From 583baa8756a71ed088b8e46c52a945218037314c Mon Sep 17 00:00:00 2001 From: Don Heyse Date: Wed, 12 Mar 2003 14:38:47 +0000 Subject: [PATCH] Switch to ANSI C comments. Removed always true tests on unsigned char. Single buffering fix.. git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@53 7f0cb862-5218-0410-a997-914c9d46530a --- freeglut-1.3/freeglut_cursor.c | 6 ++--- freeglut-1.3/freeglut_display.c | 5 ++++ freeglut-1.3/freeglut_font.c | 50 ++++++++++++++++--------------------- freeglut-1.3/freeglut_geometry.c | 6 ++--- freeglut-1.3/freeglut_internal.h | 18 ++++++------- freeglut-1.3/freeglut_joystick.c | 2 +- freeglut-1.3/freeglut_main.c | 10 ++++---- freeglut-1.3/freeglut_structure.c | 2 +- freeglut-1.3/freeglut_window.c | 35 ++++++++++++++++++++++++++ 9 files changed, 84 insertions(+), 50 deletions(-) diff --git a/freeglut-1.3/freeglut_cursor.c b/freeglut-1.3/freeglut_cursor.c index ed67eff..9d519c0 100644 --- a/freeglut-1.3/freeglut_cursor.c +++ b/freeglut-1.3/freeglut_cursor.c @@ -111,11 +111,11 @@ void FGAPIENTRY glutSetCursor( int cursorID ) /* * This is a temporary solution only... */ - // Set the cursor AND change it for this window class. + /* Set the cursor AND change it for this window class. */ # define MAP_CURSOR(a,b) case a: SetCursor( LoadCursor( NULL, b ) ); \ SetClassLong(fgStructure.Window->Window.Handle,GCL_HCURSOR,(LONG)LoadCursor(NULL,b)); \ break; - // Nuke the cursor AND change it for this window class. + /* Nuke the cursor AND change it for this window class. */ # define ZAP_CURSOR(a,b) case a: SetCursor( NULL ); \ SetClassLong(fgStructure.Window->Window.Handle,GCL_HCURSOR,(LONG)NULL); \ break; @@ -132,7 +132,7 @@ void FGAPIENTRY glutSetCursor( int cursorID ) MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT ); MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_UPARROW ); MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS ); - //MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); + /* MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); */ ZAP_CURSOR( GLUT_CURSOR_NONE, NULL ); default: diff --git a/freeglut-1.3/freeglut_display.c b/freeglut-1.3/freeglut_display.c index 9117a10..7f7e3c1 100644 --- a/freeglut-1.3/freeglut_display.c +++ b/freeglut-1.3/freeglut_display.c @@ -76,6 +76,11 @@ void FGAPIENTRY glutSwapBuffers( void ) #if TARGET_HOST_UNIX_X11 /* + * If it's single-buffered, we shouldn't be here. + */ + if ( ! fgStructure.Window->Window.DoubleBuffered ) return ; + + /* * Issue the glXSwapBuffers call and be done with it */ glXSwapBuffers( fgDisplay.Display, fgStructure.Window->Window.Handle ); diff --git a/freeglut-1.3/freeglut_font.c b/freeglut-1.3/freeglut_font.c index c971ad6..46e2219 100644 --- a/freeglut-1.3/freeglut_font.c +++ b/freeglut-1.3/freeglut_font.c @@ -209,27 +209,24 @@ void FGAPIENTRY glutBitmapString( void* fontID, const char *string ) */ for( c = 0; c < numchar; c++ ) { - if ( ( string[ c ] >= 0 ) && ( string[ c ] < 256 ) ) + if ( string[c] == '\n' ) { - if ( string[c] == '\n' ) - { - raster_position[1] -= (float)font->Height ; - glRasterPos4fv ( raster_position ) ; - } - else /* Not a carriage return, draw the bitmap character */ - { - const GLubyte* face = font->Characters[ string[ c ] - 1 ] ; - - /* - * We'll use a glBitmap call to draw the font. - */ - glBitmap( - face[ 0 ], font->Height, /* The bitmap's width and height */ - font->xorig, font->yorig, /* The origin -- what on earth? */ - (float)(face[ 0 ]), 0.0, /* The raster advance -- inc. x */ - (face + 1) /* The packed bitmap data... */ - ) ; - } + raster_position[1] -= (float)font->Height ; + glRasterPos4fv ( raster_position ) ; + } + else /* Not a carriage return, draw the bitmap character */ + { + const GLubyte* face = font->Characters[ string[ c ] - 1 ] ; + + /* + * We'll use a glBitmap call to draw the font. + */ + glBitmap( + face[ 0 ], font->Height, /* The bitmap's width and height */ + font->xorig, font->yorig, /* The origin -- what on earth? */ + (float)(face[ 0 ]), 0.0, /* The raster advance -- inc. x */ + (face + 1) /* The packed bitmap data... */ + ) ; } } @@ -278,16 +275,13 @@ int FGAPIENTRY glutBitmapLength( void* fontID, const char* string ) int numchar = strlen ( string ) ; for( c = 0; c < numchar; c++ ) { - if ( ( string[ c ] >= 0 ) && ( string[ c ] < 256 ) ) + if ( string[ c ] == '\n' ) /* Carriage return, reset the length of this line */ { - if ( string[ c ] == '\n' ) /* Carriage return, reset the length of this line */ - { - if ( length < this_line_length ) length = this_line_length ; - this_line_length = 0 ; - } - else /* Not a carriage return, increment the length of this line */ - this_line_length += *(font->Characters[ string[ c ] - 1 ]) ; + if ( length < this_line_length ) length = this_line_length ; + this_line_length = 0 ; } + else /* Not a carriage return, increment the length of this line */ + this_line_length += *(font->Characters[ string[ c ] - 1 ]) ; } if ( length < this_line_length ) length = this_line_length ; diff --git a/freeglut-1.3/freeglut_geometry.c b/freeglut-1.3/freeglut_geometry.c index 1c03a36..5fae579 100644 --- a/freeglut-1.3/freeglut_geometry.c +++ b/freeglut-1.3/freeglut_geometry.c @@ -205,7 +205,7 @@ void FGAPIENTRY glutSolidSphere( GLdouble dRadius, GLint slices, GLint stacks ) float cphi, sphi, cpsi, spsi ; glPushMatrix(); - //glScalef( radius, radius, radius ); + /* glScalef( radius, radius, radius ); */ row = calloc( sizeof(float), slices * 3 ); next = calloc( sizeof(float), slices * 3 ); @@ -984,7 +984,7 @@ void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLfloat offset[3], GL } else { - GLfloat local_offset[3] ; // Use a local variable to avoid buildup of roundoff errors + GLfloat local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */ num_levels -- ; scale /= 2.0 ; local_offset[0] = offset[0] + scale * tetrahedron_v[0][0] ; @@ -1026,7 +1026,7 @@ void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLfloat offset[3], G } else { - GLfloat local_offset[3] ; // Use a local variable to avoid buildup of roundoff errors + GLfloat local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */ num_levels -- ; scale /= 2.0 ; local_offset[0] = offset[0] + scale * tetrahedron_v[0][0] ; diff --git a/freeglut-1.3/freeglut_internal.h b/freeglut-1.3/freeglut_internal.h index 977e69d..e60d783 100644 --- a/freeglut-1.3/freeglut_internal.h +++ b/freeglut-1.3/freeglut_internal.h @@ -84,10 +84,9 @@ #include #include - /* - * This will generate errors, but I don't have any idea how to fix it (will autoconf help?) - */ + #ifndef __sgi #include + #endif #endif /* @@ -289,14 +288,15 @@ typedef struct tagSFG_Context SFG_Context; struct tagSFG_Context { #if TARGET_HOST_UNIX_X11 - Window Handle; /* The window's handle */ - GLXContext Context; /* The OpenGL context */ - XVisualInfo* VisualInfo; /* The window's visual information */ + Window Handle; /* The window's handle */ + GLXContext Context; /* The OpenGL context */ + XVisualInfo* VisualInfo; /* The window's visual information */ + int DoubleBuffered; /* Treat the window as double-buffered */ #elif TARGET_HOST_WIN32 - HWND Handle; /* The window's handle */ - HDC Device; /* The window's device context */ - HGLRC Context; /* The window's WGL context */ + HWND Handle; /* The window's handle */ + HDC Device; /* The window's device context */ + HGLRC Context; /* The window's WGL context */ #endif }; diff --git a/freeglut-1.3/freeglut_joystick.c b/freeglut-1.3/freeglut_joystick.c index bc3df83..fc2c8f6 100644 --- a/freeglut-1.3/freeglut_joystick.c +++ b/freeglut-1.3/freeglut_joystick.c @@ -540,7 +540,7 @@ void fgJoystickClose( void ) #endif free ( fgJoystick ) ; - fgJoystick = NULL ; // show joystick has been deinitialized + fgJoystick = NULL ; /* show joystick has been deinitialized */ } /* diff --git a/freeglut-1.3/freeglut_main.c b/freeglut-1.3/freeglut_main.c index 9d98284..27e3ac4 100644 --- a/freeglut-1.3/freeglut_main.c +++ b/freeglut-1.3/freeglut_main.c @@ -1189,7 +1189,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara case WM_ACTIVATE: if (LOWORD(wParam) != WA_INACTIVE) { - //glutSetCursor( fgStructure.Window->State.Cursor ); + /* glutSetCursor( fgStructure.Window->State.Cursor ); */ printf("WM_ACTIVATE: glutSetCursor( %p, %d)\n", window, window->State.Cursor ); glutSetCursor( window->State.Cursor ); @@ -1208,10 +1208,10 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara (fgStructure.Window->State.Cursor == GLUT_CURSOR_NONE)) SetCursor( NULL ); #else - // Set the cursor AND change it for this window class. + /* Set the cursor AND change it for this window class. */ # define MAP_CURSOR(a,b) case a: SetCursor( LoadCursor( NULL, b ) ); \ break; - // Nuke the cursor AND change it for this window class. + /* Nuke the cursor AND change it for this window class. */ # define ZAP_CURSOR(a,b) case a: SetCursor( NULL ); \ break; @@ -1228,7 +1228,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT ); MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_UPARROW ); MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS ); - //MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); + /* MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); */ ZAP_CURSOR( GLUT_CURSOR_NONE, NULL ); default: @@ -1697,7 +1697,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara if ( window->Callbacks.Display ) window->Callbacks.Display () ; -// lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ) ; +/* lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ) ; */ break ; /* diff --git a/freeglut-1.3/freeglut_structure.c b/freeglut-1.3/freeglut_structure.c index 2da3e1f..335168a 100644 --- a/freeglut-1.3/freeglut_structure.c +++ b/freeglut-1.3/freeglut_structure.c @@ -209,7 +209,7 @@ void fgAddToWindowDestroyList ( SFG_Window* window, GLboolean needToClose ) void fgCloseWindows () { SFG_WindowList *window_ptr = WindowsToDestroy ; - WindowsToDestroy = (SFG_WindowList*)NULL ; // In case the destroy callbacks cause more windows to be closed + WindowsToDestroy = (SFG_WindowList*)NULL ; /* In case the destroy callbacks cause more windows to be closed */ while ( window_ptr ) { diff --git a/freeglut-1.3/freeglut_window.c b/freeglut-1.3/freeglut_window.c index 6553477..7d67b61 100644 --- a/freeglut-1.3/freeglut_window.c +++ b/freeglut-1.3/freeglut_window.c @@ -361,9 +361,35 @@ void fgOpenWindow( SFG_Window* window, const char* title, int x, int y, int w, i freeglut_assert_ready; /* + * Save the window's single- or double-buffering state + */ + window->Window.DoubleBuffered = ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0 ; + + /* * Here we are upon the stage. Have the visual selected. */ window->Window.VisualInfo = fgChooseVisual(); + if ( ! window->Window.VisualInfo ) + { + /* + * The "fgChooseVisual" returned a null meaning that the visual context is not available. + * Try a couple of variations to see if they will work. + */ + if ( ! ( fgState.DisplayMode & GLUT_DOUBLE ) ) + { + /* + * Single buffering--try it doubled + */ + fgState.DisplayMode |= GLUT_DOUBLE ; + window->Window.VisualInfo = fgChooseVisual(); + } + + /* + * GLUT also checks for multi-sampling, but I don't see that anywhere else in FREEGLUT + * so I won't bother with it for the moment. + */ + } + assert( window->Window.VisualInfo != NULL ); /* @@ -515,6 +541,15 @@ void fgOpenWindow( SFG_Window* window, const char* title, int x, int y, int w, i # endif } + /* + * If it's not double-buffered, make sure the rendering is done to the front buffer. + */ + if ( ! window->Window.DoubleBuffered ) + { + glDrawBuffer ( GL_FRONT ) ; + glReadBuffer ( GL_FRONT ) ; + } + #elif TARGET_HOST_WIN32 WNDCLASS wc; -- 1.7.10.4