Hrm. I misunderstood the purpose of {window->State.Width} and
[freeglut] / src / freeglut_window.c
index f268eb3..743b94f 100644 (file)
@@ -529,12 +529,12 @@ void fgOpenWindow( SFG_Window* window, const char* title,
 #endif
 
     window->Window.DoubleBuffered =
-        ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0 ;
+        ( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0;
 
     if ( ! window->Window.DoubleBuffered )
     {
-        glDrawBuffer ( GL_FRONT ) ;
-        glReadBuffer ( GL_FRONT ) ;
+        glDrawBuffer ( GL_FRONT );
+        glReadBuffer ( GL_FRONT );
     }
     fgSetWindow( window );
 }
@@ -554,13 +554,34 @@ void fgCloseWindow( SFG_Window* window )
 
 #elif TARGET_HOST_WIN32
 
-    SendMessage( 
-        window->Window.Handle,
-        WM_CLOSE,
-        0,
-        0
-    );
+    /*
+     * Make sure we don't close a window with current context active
+     */
+    if( fgStructure.Window == window )
+        wglMakeCurrent( NULL, NULL );
 
+    /*
+     * Step through the list of windows.  If the rendering context
+     * is not being used by another window, then we delete it.
+     */
+    {
+        int used = FALSE ;
+        SFG_Window *iter ;
+
+        for( iter = (SFG_Window *)fgStructure.Windows.First;
+             iter;
+             iter = (SFG_Window *)iter->Node.Next )
+        {
+            if( ( iter->Window.Context == window->Window.Context ) &&
+                ( iter != window ) )
+                used = TRUE;
+        }
+
+        if( ! used )
+            wglDeleteContext( window->Window.Context );
+    }
+
+    DestroyWindow( window->Window.Handle );
 #endif
 }
 
@@ -589,6 +610,7 @@ int FGAPIENTRY glutCreateSubWindow( int parentID, int x, int y, int w, int h )
     parent = fgWindowByID( parentID );
     freeglut_return_val_if_fail( parent != NULL, 0 );
     window = fgCreateWindow( parent, "", x, y, w, h, GL_FALSE, GL_FALSE );
+    window->State.OldHeight = window->State.OldWidth = -1;
     return window->ID;
 }
 
@@ -601,7 +623,7 @@ void FGAPIENTRY glutDestroyWindow( int windowID )
     freeglut_return_if_fail( window != NULL );
     {
         fgExecutionState ExecState = fgState.ExecState;
-        fgAddToWindowDestroyList( window, GL_TRUE );
+        fgAddToWindowDestroyList( window );
         fgState.ExecState = ExecState;
     }
 }
@@ -625,7 +647,7 @@ void FGAPIENTRY glutSetWindow( int ID )
         return;
     }
 
-    fgSetWindow( window ) ;
+    fgSetWindow( window );
 }
 
 /*