Adding a more comprehensive warning message if "CreateDC" failed, per e-mail from...
[freeglut] / src / freeglut_init.c
index bf5b5ac..7cccc35 100644 (file)
@@ -25,6 +25,7 @@
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#define FREEGLUT_BUILDING_LIB
 #include <GL/freeglut.h>
 #include "freeglut_internal.h"
 
@@ -83,12 +84,14 @@ SFG_State fgState = { { -1, -1, GL_FALSE },  /* Position */
                       GLUT_EXEC_STATE_INIT,   /* ExecState */
                       NULL,                   /* ProgramName */
                       GL_FALSE,               /* JoysticksInitialised */
+                      0,                      /* NumActiveJoysticks */
                       GL_FALSE,               /* InputDevsInitialised */
-                      0,                      /* AuxiliaryBufferNumber */
-                      0,                      /* SampleNumber */
+                      1,                      /* AuxiliaryBufferNumber */
+                      4,                      /* SampleNumber */
                       1,                      /* MajorVersion */
                       0,                      /* MajorVersion */
-                      0                       /* ContextFlags */
+                      0,                      /* ContextFlags */
+                      0                       /* ContextProfile */
 };
 
 
@@ -308,7 +311,7 @@ static void fghInitialize( const char* displayName )
 
     /* What we need to do is to initialize the fgDisplay global structure here. */
     fgDisplay.Instance = GetModuleHandle( NULL );
-
+    fgDisplay.DisplayName=strdup(displayName);
     atom = GetClassInfo( fgDisplay.Instance, _T("FREEGLUT"), &wc );
 
     if( atom == 0 )
@@ -360,7 +363,24 @@ static void fghInitialize( const char* displayName )
 
         ReleaseDC( desktop, context );
     }
-
+    /* If we have a DisplayName try to use it for metrics */
+    if( fgDisplay.DisplayName )
+    {
+        HDC context = CreateDC(fgDisplay.DisplayName,0,0,0);
+        if( context )
+        {
+           fgDisplay.ScreenWidth  = GetDeviceCaps( context, HORZRES );
+           fgDisplay.ScreenHeight = GetDeviceCaps( context, VERTRES );
+           fgDisplay.ScreenWidthMM  = GetDeviceCaps( context, HORZSIZE );
+           fgDisplay.ScreenHeightMM = GetDeviceCaps( context, VERTSIZE );
+           DeleteDC(context);
+        }
+        else
+           fgWarning("fghInitialize: "
+                     "CreateDC failed, Screen size info may be incorrect\n"
+          "This is quite likely caused by a bad '-display' parameter");
+      
+    }
     /* Set the timer granularity to 1 ms */
     timeBeginPeriod ( 1 );
 
@@ -424,6 +444,7 @@ void fgDeinitialize( void )
     fgState.MajorVersion = 1;
     fgState.MinorVersion = 0;
     fgState.ContextFlags = 0;
+    fgState.ContextProfile = 0;
 
     fgState.Initialised = GL_FALSE;
 
@@ -485,6 +506,11 @@ void fgDeinitialize( void )
     XCloseDisplay( fgDisplay.Display );
 
 #elif TARGET_HOST_MS_WINDOWS
+    if( fgDisplay.DisplayName )
+    {
+        free( fgDisplay.DisplayName );
+        fgDisplay.DisplayName = NULL;
+    }
 
     /* Reset the timer granularity */
     timeEndPeriod ( 1 );
@@ -697,6 +723,7 @@ void FGAPIENTRY glutInit( int* pargc, char** argv )
 #ifndef _WIN32_WCE
     {
         const char *fps = getenv( "GLUT_FPS" );
+
         if( fps )
         {
             int interval;
@@ -709,7 +736,7 @@ void FGAPIENTRY glutInit( int* pargc, char** argv )
         }
     }
 
-    displayName = getenv( "DISPLAY");
+    displayName = getenv( "DISPLAY" );
 
     for( i = 1; i < argc; i++ )
     {
@@ -824,6 +851,16 @@ void FGAPIENTRY glutInit( int* pargc, char** argv )
     }
 }
 
+#if TARGET_HOST_MS_WINDOWS
+void (__cdecl *__glutExitFunc)( int return_value ) = NULL;
+
+void FGAPIENTRY __glutInitWithExit( int *pargc, char **argv, void (__cdecl *exit_function)(int) )
+{
+  __glutExitFunc = exit_function;
+  glutInit(pargc, argv);
+}
+#endif
+
 /*
  * Undoes all the "glutInit" stuff
  */
@@ -898,6 +935,7 @@ void FGAPIENTRY glutInitDisplayString( const char* displayMode )
     buffer[len] = '\0';
 
     token = strtok ( buffer, " \t" );
+
     while ( token )
     {
         /* Process this token */
@@ -1099,4 +1137,10 @@ void FGAPIENTRY glutInitContextFlags( int flags )
     fgState.ContextFlags = flags;
 }
 
+void FGAPIENTRY glutInitContextProfile( int profile )
+{
+    /* We will make use of this value when creating a new OpenGL context... */
+    fgState.ContextProfile = profile;
+}
+
 /*** END OF FILE ***/