Fixing two minor bugs, adding comments
[freeglut] / src / freeglut_window.c
index 5255bb2..4a702ad 100644 (file)
@@ -30,7 +30,7 @@
 
 #if TARGET_HOST_WINCE
 #include <aygshell.h>
-#pragma comment( lib, "Aygshell.lib" )
+#pragma comment( lib, "Aygshell.lib" ) /* library pragmas are bad */
 
 static wchar_t* fghWstrFromStr(const char* str)
 {
@@ -184,6 +184,9 @@ GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
     if( fgState.DisplayMode & GLUT_DOUBLE )
         flags |= PFD_DOUBLEBUFFER;
 
+    if( fgState.DisplayMode & GLUT_STEREO )
+        flags |= PFD_STEREO;
+
 #if defined(_MSC_VER)
 #pragma message( "fgSetupPixelFormat(): there is still some work to do here!" )
 #endif
@@ -380,14 +383,14 @@ void fgOpenWindow( SFG_Window* window, const char* title,
         {
             fgStructure.MenuContext =
                 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
-            fgStructure.MenuContext->VisualInfo = window->Window.VisualInfo;
-            fgStructure.MenuContext->Context = glXCreateContext(
-                fgDisplay.Display, fgStructure.MenuContext->VisualInfo,
+            fgStructure.MenuContext->MVisualInfo = window->Window.VisualInfo;
+            fgStructure.MenuContext->MContext = glXCreateContext(
+                fgDisplay.Display, fgStructure.MenuContext->MVisualInfo,
                 NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
             );
         }
 
-        /* window->Window.Context = fgStructure.MenuContext->Context; */
+        /* window->Window.Context = fgStructure.MenuContext->MContext; */
         window->Window.Context = glXCreateContext(
             fgDisplay.Display, window->Window.VisualInfo,
             NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
@@ -618,6 +621,7 @@ void fgCloseWindow( SFG_Window* window )
 #if TARGET_HOST_UNIX_X11
 
     glXDestroyContext( fgDisplay.Display, window->Window.Context );
+    XFree( window->Window.VisualInfo );
     XDestroyWindow( fgDisplay.Display, window->Window.Handle );
     XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
 
@@ -760,10 +764,11 @@ void FGAPIENTRY glutSetWindow( int ID )
  */
 int FGAPIENTRY glutGetWindow( void )
 {
+    SFG_Window *win = fgStructure.CurrentWindow;
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetWindow" );
-    if( fgStructure.CurrentWindow == NULL )
-        return 0;
-    return fgStructure.CurrentWindow->ID;
+    while ( win && win->IsMenu )
+        win = win->Parent;
+    return win ? win->ID : 0;
 }
 
 /*