-\r
-/* Copyright (c) Mark J. Kilgard, 1994, 1997. */\r
-\r
-/* This program is freely distributable without licensing fees\r
- and is provided without guarantee or warrantee expressed or\r
- implied. This program is -not- in the public domain. */\r
-\r
-#ifdef __VMS\r
-#include <GL/vms_x_fix.h>\r
-#endif\r
-\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include <stdio.h>\r
-\r
-#if !defined(_WIN32) && !defined(__OS2__)\r
- #include <X11/Xlib.h>\r
- #include <X11/Xatom.h>\r
-#endif\r
-\r
-/* SGI optimization introduced in IRIX 6.3 to avoid X server\r
- round trips for interning common X atoms. */\r
-#if defined(_SGI_EXTRA_PREDEFINES) && !defined(NO_FAST_ATOMS)\r
-#include <X11/SGIFastAtom.h>\r
-#else\r
-#define XSGIFastInternAtom(dpy,string,fast_name,how) XInternAtom(dpy,string,how)\r
-#endif\r
-\r
-#include "glutint.h"\r
-\r
-/* GLUT inter-file variables */\r
-/* *INDENT-OFF* */\r
-char *__glutProgramName = NULL;\r
-int __glutArgc = 0;\r
-char **__glutArgv = NULL;\r
-char *__glutGeometry = NULL;\r
-Display *__glutDisplay = NULL;\r
-int __glutScreen;\r
-Window __glutRoot;\r
-int __glutScreenHeight;\r
-int __glutScreenWidth;\r
-GLboolean __glutIconic = GL_FALSE;\r
-GLboolean __glutDebug = GL_FALSE;\r
-unsigned int __glutDisplayMode =\r
- GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH;\r
-char *__glutDisplayString = NULL;\r
-int __glutConnectionFD;\r
-XSizeHints __glutSizeHints = {0};\r
-int __glutInitWidth = 300, __glutInitHeight = 300;\r
-int __glutInitX = -1, __glutInitY = -1;\r
-GLboolean __glutForceDirect = GL_FALSE,\r
- __glutTryDirect = GL_TRUE;\r
-Atom __glutWMDeleteWindow;\r
-/* *INDENT-ON* */\r
-\r
-#ifdef _WIN32\r
-void (__cdecl *__glutExitFunc)(int retval) = NULL;\r
-#endif\r
-\r
-static Bool synchronize = False;\r
-\r
-#if defined(__OS2__)\r
-\r
-MRESULT EXPENTRY GlutWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );\r
-MRESULT EXPENTRY GlutWindowChildProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );\r
-\r
-\r
-void __glutOpenOS2Connection(char* display)\r
-{\r
- static char *classname=NULL;\r
-extern HAB hab; /* PM anchor block handle */\r
-ERRORID erridErrorCode;/* last error id code */\r
-int ii;\r
-\r
- /* Make sure we register the window only once. */\r
- if(classname)\r
- return;\r
-\r
- classname = "GLUT";\r
-\r
- if ( !WinRegisterClass( hab, /* PM anchor block handle */\r
- classname,/* window class name */\r
- GlutWindowProc,/* address of window procedure*/\r
- CS_SIZEREDRAW, /* |CS_SYNCPAINT size changes cause redrawing */\r
- 0UL ) ) /* window data */\r
- { erridErrorCode = WinGetLastError(hab);\r
- ii = erridErrorCode;\r
- return;\r
- }\r
-\r
- classname = "GLUTCHILD";\r
-\r
- if ( !WinRegisterClass( hab, /* PM anchor block handle */\r
- classname,/* window class name */\r
- GlutWindowChildProc,/* address of window procedure*/\r
- CS_SIZEREDRAW, /* size changes cause redrawing */\r
- 0UL ) ) /* window data */\r
- { erridErrorCode = WinGetLastError(hab);\r
- ii = erridErrorCode;\r
- return;\r
- }\r
-\r
- __glutScreenWidth = GetSystemMetrics(SM_CXSCREEN);\r
- __glutScreenHeight = GetSystemMetrics(SM_CYSCREEN);\r
-\r
- /* Set the root window to NULL because windows creates a top-level\r
- window when the parent is NULL. X creates a top-level window\r
- when the parent is the root window. */\r
- __glutRoot = NULLHANDLE;\r
-\r
- /* Set the display to 1 -- we shouldn't be using this anywhere\r
- (except as an argument to X calls). */\r
- __glutDisplay = (Display*)1;\r
-\r
- /* There isn't any concept of multiple screens in Win32, therefore,\r
- we don't need to keep track of the screen we're on... it's always\r
- the same one. */\r
- __glutScreen = 0;\r
-}\r
-\r
-#elif defined(_WIN32)\r
-\r
-#ifdef __BORLANDC__\r
-#include <float.h> /* For masking floating point exceptions. */\r
-#endif\r
-\r
-void\r
-__glutOpenWin32Connection(char* display)\r
-{\r
- static char *classname;\r
- WNDCLASS wc;\r
- HINSTANCE hInstance = GetModuleHandle(NULL);\r
-\r
- /* Make sure we register the window only once. */\r
- if(classname)\r
- return;\r
-\r
-#ifdef __BORLANDC__\r
- /* Under certain conditions (e.g. while rendering solid surfaces with\r
- lighting enabled) Microsoft OpenGL libraries cause some illegal\r
- operations like floating point overflow or division by zero. The\r
- default behaviour of Microsoft compilers is to mask (ignore)\r
- floating point exceptions, while Borland compilers do not. The\r
- following function of Borland RTL allows to mask exceptions.\r
- Advice from Pier Giorgio Esposito (mc2172@mclink.it). */\r
- _control87(MCW_EM,MCW_EM);\r
-#endif\r
-\r
- classname = "GLUT";\r
-\r
- /* Clear (important!) and then fill in the window class structure. */\r
- memset(&wc, 0, sizeof(WNDCLASS));\r
- wc.style = CS_OWNDC;\r
- wc.lpfnWndProc = (WNDPROC)__glutWindowProc;\r
- wc.hInstance = hInstance;\r
- wc.hIcon = LoadIcon(hInstance, "GLUT_ICON");\r
- wc.hCursor = LoadCursor(hInstance, IDC_ARROW);\r
- wc.hbrBackground = NULL;\r
- wc.lpszMenuName = NULL;\r
- wc.lpszClassName = classname;\r
-\r
- /* Fill in a default icon if one isn't specified as a resource. */\r
- if(!wc.hIcon)\r
- wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);\r
-\r
- if(!RegisterClass(&wc)) {\r
- __glutFatalError("RegisterClass() failed:"\r
- "Cannot register GLUT window class.");\r
- }\r
-\r
- __glutScreenWidth = GetSystemMetrics(SM_CXSCREEN);\r
- __glutScreenHeight = GetSystemMetrics(SM_CYSCREEN);\r
-\r
- /* Set the root window to NULL because windows creates a top-level\r
- window when the parent is NULL. X creates a top-level window\r
- when the parent is the root window. */\r
- __glutRoot = NULL;\r
-\r
- /* Set the display to 1 -- we shouldn't be using this anywhere\r
- (except as an argument to X calls). */\r
- __glutDisplay = (Display*)1;\r
-\r
- /* There isn't any concept of multiple screens in Win32, therefore,\r
- we don't need to keep track of the screen we're on... it's always\r
- the same one. */\r
- __glutScreen = 0;\r
-}\r
-#else /* !_WIN32 */\r
-void\r
-__glutOpenXConnection(char *display)\r
-{\r
- int errorBase, eventBase;\r
-\r
- __glutDisplay = XOpenDisplay(display);\r
- if (!__glutDisplay)\r
- __glutFatalError("could not open display: %s",\r
- XDisplayName(display));\r
- if (synchronize)\r
- XSynchronize(__glutDisplay, True);\r
- if (!glXQueryExtension(__glutDisplay, &errorBase, &eventBase))\r
- __glutFatalError(\r
- "OpenGL GLX extension not supported by display: %s",\r
- XDisplayName(display));\r
- __glutScreen = DefaultScreen(__glutDisplay);\r
- __glutRoot = RootWindow(__glutDisplay, __glutScreen);\r
- __glutScreenWidth = DisplayWidth(__glutDisplay, __glutScreen);\r
- __glutScreenHeight = DisplayHeight(__glutDisplay,\r
- __glutScreen);\r
- __glutConnectionFD = ConnectionNumber(__glutDisplay);\r
- __glutWMDeleteWindow = XSGIFastInternAtom(__glutDisplay,\r
- "WM_DELETE_WINDOW", SGI_XA_WM_DELETE_WINDOW, False);\r
-}\r
-#endif /* _WIN32 */\r
-\r
-void\r
-#ifdef OLD_VMS\r
- __glutInitTime(struct timeval6 *beginning)\r
-#else\r
- __glutInitTime(struct timeval *beginning)\r
-#endif\r
-{\r
- static int beenhere = 0;\r
-#ifdef OLD_VMS\r
- static struct timeval6 genesis;\r
-#else\r
- static struct timeval genesis;\r
-#endif\r
-\r
- if (!beenhere) {\r
- GETTIMEOFDAY(&genesis);\r
- beenhere = 1;\r
- }\r
- *beginning = genesis;\r
-}\r
-\r
-static void\r
-removeArgs(int *argcp, char **argv, int numToRemove)\r
-{\r
- int i, j;\r
-\r
- for (i = 0, j = numToRemove; argv[j]; i++, j++) {\r
- argv[i] = argv[j];\r
- }\r
- argv[i] = NULL;\r
- *argcp -= numToRemove;\r
-}\r
-\r
-void GLUTAPIENTRY\r
-glutInit(int *argcp, char **argv)\r
-{\r
- char *display = NULL;\r
- char *str, *geometry = NULL;\r
-#ifdef OLD_VMS\r
- struct timeval6 unused;\r
-#else\r
- struct timeval unused;\r
-#endif\r
- int i;\r
-\r
- if (__glutDisplay) {\r
- __glutWarning("glutInit being called a second time.");\r
- return;\r
- }\r
- /* Determine temporary program name. */\r
- str = strrchr(argv[0], '/');\r
- if (str == NULL) {\r
- __glutProgramName = argv[0];\r
- } else {\r
- __glutProgramName = str + 1;\r
- }\r
-\r
- /* Make private copy of command line arguments. */\r
- __glutArgc = *argcp;\r
- __glutArgv = (char **) malloc(__glutArgc * sizeof(char *));\r
- if (!__glutArgv)\r
- __glutFatalError("out of memory.");\r
- for (i = 0; i < __glutArgc; i++) {\r
- __glutArgv[i] = __glutStrdup(argv[i]);\r
- if (!__glutArgv[i])\r
- __glutFatalError("out of memory.");\r
- }\r
-\r
- /* determine permanent program name */\r
- str = strrchr(__glutArgv[0], '/');\r
- if (str == NULL) {\r
- __glutProgramName = __glutArgv[0];\r
- } else {\r
- __glutProgramName = str + 1;\r
- }\r
-\r
- /* parse arguments for standard options */\r
- for (i = 1; i < __glutArgc; i++) {\r
- if (!strcmp(__glutArgv[i], "-display")) {\r
-#if defined(_WIN32)\r
- __glutWarning("-display option not supported by Win32 GLUT.");\r
-#endif\r
- if (++i >= __glutArgc) {\r
- __glutFatalError(\r
- "follow -display option with X display name.");\r
- }\r
- display = __glutArgv[i];\r
- removeArgs(argcp, &argv[1], 2);\r
- } else if (!strcmp(__glutArgv[i], "-geometry")) {\r
- if (++i >= __glutArgc) {\r
- __glutFatalError(\r
- "follow -geometry option with geometry parameter.");\r
- }\r
- geometry = __glutArgv[i];\r
- removeArgs(argcp, &argv[1], 2);\r
- } else if (!strcmp(__glutArgv[i], "-direct")) {\r
-#if defined(_WIN32)\r
- __glutWarning("-direct option not supported by Win32 GLUT.");\r
-#endif\r
- if (!__glutTryDirect)\r
- __glutFatalError(\r
- "cannot force both direct and indirect rendering.");\r
- __glutForceDirect = GL_TRUE;\r
- removeArgs(argcp, &argv[1], 1);\r
- } else if (!strcmp(__glutArgv[i], "-indirect")) {\r
-#if defined(_WIN32)\r
- __glutWarning("-indirect option not supported by Win32 GLUT.");\r
-#endif\r
- if (__glutForceDirect)\r
- __glutFatalError(\r
- "cannot force both direct and indirect rendering.");\r
- __glutTryDirect = GL_FALSE;\r
- removeArgs(argcp, &argv[1], 1);\r
- } else if (!strcmp(__glutArgv[i], "-iconic")) {\r
- __glutIconic = GL_TRUE;\r
- removeArgs(argcp, &argv[1], 1);\r
- } else if (!strcmp(__glutArgv[i], "-gldebug")) {\r
- __glutDebug = GL_TRUE;\r
- removeArgs(argcp, &argv[1], 1);\r
- } else if (!strcmp(__glutArgv[i], "-sync")) {\r
-#if defined(_WIN32)\r
- __glutWarning("-sync option not supported by Win32 GLUT.");\r
-#endif\r
- synchronize = GL_TRUE;\r
- removeArgs(argcp, &argv[1], 1);\r
- } else {\r
- /* Once unknown option encountered, stop command line\r
- processing. */\r
- break;\r
- }\r
- }\r
-#if defined(__OS2__)\r
- __glutOpenOS2Connection(display);\r
-#elif defined(_WIN32)\r
- __glutOpenWin32Connection(display);\r
-#else\r
- __glutOpenXConnection(display);\r
-#endif\r
- if (geometry) {\r
- int flags, x, y, width, height;\r
-\r
- /* Fix bogus "{width|height} may be used before set"\r
- warning */\r
- width = 0;\r
- height = 0;\r
-\r
- flags = XParseGeometry(geometry, &x, &y,\r
- (unsigned int *) &width, (unsigned int *) &height);\r
- if (WidthValue & flags) {\r
- /* Careful because X does not allow zero or negative\r
- width windows */\r
- if (width > 0)\r
- __glutInitWidth = width;\r
- }\r
- if (HeightValue & flags) {\r
- /* Careful because X does not allow zero or negative\r
- height windows */\r
- if (height > 0)\r
- __glutInitHeight = height;\r
- }\r
- glutInitWindowSize(__glutInitWidth, __glutInitHeight);\r
- if (XValue & flags) {\r
- if (XNegative & flags)\r
- x = DisplayWidth(__glutDisplay, __glutScreen) +\r
- x - __glutSizeHints.width;\r
- /* Play safe: reject negative X locations */\r
- if (x >= 0)\r
- __glutInitX = x;\r
- }\r
- if (YValue & flags) {\r
- if (YNegative & flags)\r
- y = DisplayHeight(__glutDisplay, __glutScreen) +\r
- y - __glutSizeHints.height;\r
- /* Play safe: reject negative Y locations */\r
- if (y >= 0)\r
- __glutInitY = y;\r
- }\r
- glutInitWindowPosition(__glutInitX, __glutInitY);\r
- }\r
- __glutInitTime(&unused);\r
-\r
- /* check if GLUT_FPS env var is set */\r
- {\r
- const char *fps = getenv("GLUT_FPS");\r
- if (fps) {\r
- sscanf(fps, "%d", &__glutFPS);\r
- if (__glutFPS <= 0)\r
- __glutFPS = 5000; /* 5000 milliseconds */\r
- }\r
- }\r
-}\r
-\r
-#ifdef _WIN32\r
-void APIENTRY\r
-__glutInitWithExit(int *argcp, char **argv, void (__cdecl *exitfunc)(int))\r
-{\r
- __glutExitFunc = exitfunc;\r
- glutInit(argcp, argv);\r
-}\r
-#endif\r
-\r
-/* CENTRY */\r
-void GLUTAPIENTRY\r
-glutInitWindowPosition(int x, int y)\r
-{\r
- __glutInitX = x;\r
- __glutInitY = y;\r
- if (x >= 0 && y >= 0) {\r
- __glutSizeHints.x = x;\r
- __glutSizeHints.y = y;\r
- __glutSizeHints.flags |= USPosition;\r
- } else {\r
- __glutSizeHints.flags &= ~USPosition;\r
- }\r
-}\r
-\r
-void GLUTAPIENTRY\r
-glutInitWindowSize(int width, int height)\r
-{\r
- __glutInitWidth = width;\r
- __glutInitHeight = height;\r
- if (width > 0 && height > 0) {\r
- __glutSizeHints.width = width;\r
- __glutSizeHints.height = height;\r
- __glutSizeHints.flags |= USSize;\r
- } else {\r
- __glutSizeHints.flags &= ~USSize;\r
- }\r
-}\r
-\r
-void GLUTAPIENTRY\r
-glutInitDisplayMode(unsigned int mask)\r
-{\r
- __glutDisplayMode = mask;\r
-}\r
-\r
-/* ENDCENTRY */\r
+
+/* Copyright (c) Mark J. Kilgard, 1994, 1997. */
+
+/* This program is freely distributable without licensing fees
+ and is provided without guarantee or warrantee expressed or
+ implied. This program is -not- in the public domain. */
+
+#ifdef __VMS
+#include <GL/vms_x_fix.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#if !defined(_WIN32) && !defined(__OS2__)
+ #include <X11/Xlib.h>
+ #include <X11/Xatom.h>
+#endif
+
+/* SGI optimization introduced in IRIX 6.3 to avoid X server
+ round trips for interning common X atoms. */
+#if defined(_SGI_EXTRA_PREDEFINES) && !defined(NO_FAST_ATOMS)
+#include <X11/SGIFastAtom.h>
+#else
+#define XSGIFastInternAtom(dpy,string,fast_name,how) XInternAtom(dpy,string,how)
+#endif
+
+#include "glutint.h"
+
+/* GLUT inter-file variables */
+/* *INDENT-OFF* */
+char *__glutProgramName = NULL;
+int __glutArgc = 0;
+char **__glutArgv = NULL;
+char *__glutGeometry = NULL;
+Display *__glutDisplay = NULL;
+int __glutScreen;
+Window __glutRoot;
+int __glutScreenHeight;
+int __glutScreenWidth;
+GLboolean __glutIconic = GL_FALSE;
+GLboolean __glutDebug = GL_FALSE;
+unsigned int __glutDisplayMode =
+ GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH;
+char *__glutDisplayString = NULL;
+int __glutConnectionFD;
+XSizeHints __glutSizeHints = {0};
+int __glutInitWidth = 300, __glutInitHeight = 300;
+int __glutInitX = -1, __glutInitY = -1;
+GLboolean __glutForceDirect = GL_FALSE,
+ __glutTryDirect = GL_TRUE;
+Atom __glutWMDeleteWindow;
+/* *INDENT-ON* */
+
+#ifdef _WIN32
+void (__cdecl *__glutExitFunc)(int retval) = NULL;
+#endif
+
+static Bool synchronize = False;
+
+#if defined(__OS2__)
+
+MRESULT EXPENTRY GlutWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
+MRESULT EXPENTRY GlutWindowChildProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
+
+
+void __glutOpenOS2Connection(char* display)
+{
+ static char *classname=NULL;
+extern HAB hab; /* PM anchor block handle */
+ERRORID erridErrorCode;/* last error id code */
+int ii;
+
+ /* Make sure we register the window only once. */
+ if(classname)
+ return;
+
+ classname = "GLUT";
+
+ if ( !WinRegisterClass( hab, /* PM anchor block handle */
+ classname,/* window class name */
+ GlutWindowProc,/* address of window procedure*/
+ CS_SIZEREDRAW, /* |CS_SYNCPAINT size changes cause redrawing */
+ 0UL ) ) /* window data */
+ { erridErrorCode = WinGetLastError(hab);
+ ii = erridErrorCode;
+ return;
+ }
+
+ classname = "GLUTCHILD";
+
+ if ( !WinRegisterClass( hab, /* PM anchor block handle */
+ classname,/* window class name */
+ GlutWindowChildProc,/* address of window procedure*/
+ CS_SIZEREDRAW, /* size changes cause redrawing */
+ 0UL ) ) /* window data */
+ { erridErrorCode = WinGetLastError(hab);
+ ii = erridErrorCode;
+ return;
+ }
+
+ __glutScreenWidth = GetSystemMetrics(SM_CXSCREEN);
+ __glutScreenHeight = GetSystemMetrics(SM_CYSCREEN);
+
+ /* Set the root window to NULL because windows creates a top-level
+ window when the parent is NULL. X creates a top-level window
+ when the parent is the root window. */
+ __glutRoot = NULLHANDLE;
+
+ /* Set the display to 1 -- we shouldn't be using this anywhere
+ (except as an argument to X calls). */
+ __glutDisplay = (Display*)1;
+
+ /* There isn't any concept of multiple screens in Win32, therefore,
+ we don't need to keep track of the screen we're on... it's always
+ the same one. */
+ __glutScreen = 0;
+}
+
+#elif defined(_WIN32)
+
+#ifdef __BORLANDC__
+#include <float.h> /* For masking floating point exceptions. */
+#endif
+
+void
+__glutOpenWin32Connection(char* display)
+{
+ static char *classname;
+ WNDCLASS wc;
+ HINSTANCE hInstance = GetModuleHandle(NULL);
+
+ /* Make sure we register the window only once. */
+ if(classname)
+ return;
+
+#ifdef __BORLANDC__
+ /* Under certain conditions (e.g. while rendering solid surfaces with
+ lighting enabled) Microsoft OpenGL libraries cause some illegal
+ operations like floating point overflow or division by zero. The
+ default behaviour of Microsoft compilers is to mask (ignore)
+ floating point exceptions, while Borland compilers do not. The
+ following function of Borland RTL allows to mask exceptions.
+ Advice from Pier Giorgio Esposito (mc2172@mclink.it). */
+ _control87(MCW_EM,MCW_EM);
+#endif
+
+ classname = "GLUT";
+
+ /* Clear (important!) and then fill in the window class structure. */
+ memset(&wc, 0, sizeof(WNDCLASS));
+ wc.style = CS_OWNDC;
+ wc.lpfnWndProc = (WNDPROC)__glutWindowProc;
+ wc.hInstance = hInstance;
+ wc.hIcon = LoadIcon(hInstance, "GLUT_ICON");
+ wc.hCursor = LoadCursor(hInstance, IDC_ARROW);
+ wc.hbrBackground = NULL;
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = classname;
+
+ /* Fill in a default icon if one isn't specified as a resource. */
+ if(!wc.hIcon)
+ wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
+
+ if(!RegisterClass(&wc)) {
+ __glutFatalError("RegisterClass() failed:"
+ "Cannot register GLUT window class.");
+ }
+
+ __glutScreenWidth = GetSystemMetrics(SM_CXSCREEN);
+ __glutScreenHeight = GetSystemMetrics(SM_CYSCREEN);
+
+ /* Set the root window to NULL because windows creates a top-level
+ window when the parent is NULL. X creates a top-level window
+ when the parent is the root window. */
+ __glutRoot = NULL;
+
+ /* Set the display to 1 -- we shouldn't be using this anywhere
+ (except as an argument to X calls). */
+ __glutDisplay = (Display*)1;
+
+ /* There isn't any concept of multiple screens in Win32, therefore,
+ we don't need to keep track of the screen we're on... it's always
+ the same one. */
+ __glutScreen = 0;
+}
+#else /* !_WIN32 */
+void
+__glutOpenXConnection(char *display)
+{
+ int errorBase, eventBase;
+
+ __glutDisplay = XOpenDisplay(display);
+ if (!__glutDisplay)
+ __glutFatalError("could not open display: %s",
+ XDisplayName(display));
+ if (synchronize)
+ XSynchronize(__glutDisplay, True);
+ if (!glXQueryExtension(__glutDisplay, &errorBase, &eventBase))
+ __glutFatalError(
+ "OpenGL GLX extension not supported by display: %s",
+ XDisplayName(display));
+ __glutScreen = DefaultScreen(__glutDisplay);
+ __glutRoot = RootWindow(__glutDisplay, __glutScreen);
+ __glutScreenWidth = DisplayWidth(__glutDisplay, __glutScreen);
+ __glutScreenHeight = DisplayHeight(__glutDisplay,
+ __glutScreen);
+ __glutConnectionFD = ConnectionNumber(__glutDisplay);
+ __glutWMDeleteWindow = XSGIFastInternAtom(__glutDisplay,
+ "WM_DELETE_WINDOW", SGI_XA_WM_DELETE_WINDOW, False);
+}
+#endif /* _WIN32 */
+
+void
+#ifdef OLD_VMS
+ __glutInitTime(struct timeval6 *beginning)
+#else
+ __glutInitTime(struct timeval *beginning)
+#endif
+{
+ static int beenhere = 0;
+#ifdef OLD_VMS
+ static struct timeval6 genesis;
+#else
+ static struct timeval genesis;
+#endif
+
+ if (!beenhere) {
+ GETTIMEOFDAY(&genesis);
+ beenhere = 1;
+ }
+ *beginning = genesis;
+}
+
+static void
+removeArgs(int *argcp, char **argv, int numToRemove)
+{
+ int i, j;
+
+ for (i = 0, j = numToRemove; argv[j]; i++, j++) {
+ argv[i] = argv[j];
+ }
+ argv[i] = NULL;
+ *argcp -= numToRemove;
+}
+
+void GLUTAPIENTRY
+glutInit(int *argcp, char **argv)
+{
+ char *display = NULL;
+ char *str, *geometry = NULL;
+#ifdef OLD_VMS
+ struct timeval6 unused;
+#else
+ struct timeval unused;
+#endif
+ int i;
+
+ if (__glutDisplay) {
+ __glutWarning("glutInit being called a second time.");
+ return;
+ }
+ /* Determine temporary program name. */
+ str = strrchr(argv[0], '/');
+ if (str == NULL) {
+ __glutProgramName = argv[0];
+ } else {
+ __glutProgramName = str + 1;
+ }
+
+ /* Make private copy of command line arguments. */
+ __glutArgc = *argcp;
+ __glutArgv = (char **) malloc(__glutArgc * sizeof(char *));
+ if (!__glutArgv)
+ __glutFatalError("out of memory.");
+ for (i = 0; i < __glutArgc; i++) {
+ __glutArgv[i] = __glutStrdup(argv[i]);
+ if (!__glutArgv[i])
+ __glutFatalError("out of memory.");
+ }
+
+ /* determine permanent program name */
+ str = strrchr(__glutArgv[0], '/');
+ if (str == NULL) {
+ __glutProgramName = __glutArgv[0];
+ } else {
+ __glutProgramName = str + 1;
+ }
+
+ /* parse arguments for standard options */
+ for (i = 1; i < __glutArgc; i++) {
+ if (!strcmp(__glutArgv[i], "-display")) {
+#if defined(_WIN32)
+ __glutWarning("-display option not supported by Win32 GLUT.");
+#endif
+ if (++i >= __glutArgc) {
+ __glutFatalError(
+ "follow -display option with X display name.");
+ }
+ display = __glutArgv[i];
+ removeArgs(argcp, &argv[1], 2);
+ } else if (!strcmp(__glutArgv[i], "-geometry")) {
+ if (++i >= __glutArgc) {
+ __glutFatalError(
+ "follow -geometry option with geometry parameter.");
+ }
+ geometry = __glutArgv[i];
+ removeArgs(argcp, &argv[1], 2);
+ } else if (!strcmp(__glutArgv[i], "-direct")) {
+#if defined(_WIN32)
+ __glutWarning("-direct option not supported by Win32 GLUT.");
+#endif
+ if (!__glutTryDirect)
+ __glutFatalError(
+ "cannot force both direct and indirect rendering.");
+ __glutForceDirect = GL_TRUE;
+ removeArgs(argcp, &argv[1], 1);
+ } else if (!strcmp(__glutArgv[i], "-indirect")) {
+#if defined(_WIN32)
+ __glutWarning("-indirect option not supported by Win32 GLUT.");
+#endif
+ if (__glutForceDirect)
+ __glutFatalError(
+ "cannot force both direct and indirect rendering.");
+ __glutTryDirect = GL_FALSE;
+ removeArgs(argcp, &argv[1], 1);
+ } else if (!strcmp(__glutArgv[i], "-iconic")) {
+ __glutIconic = GL_TRUE;
+ removeArgs(argcp, &argv[1], 1);
+ } else if (!strcmp(__glutArgv[i], "-gldebug")) {
+ __glutDebug = GL_TRUE;
+ removeArgs(argcp, &argv[1], 1);
+ } else if (!strcmp(__glutArgv[i], "-sync")) {
+#if defined(_WIN32)
+ __glutWarning("-sync option not supported by Win32 GLUT.");
+#endif
+ synchronize = GL_TRUE;
+ removeArgs(argcp, &argv[1], 1);
+ } else {
+ /* Once unknown option encountered, stop command line
+ processing. */
+ break;
+ }
+ }
+#if defined(__OS2__)
+ __glutOpenOS2Connection(display);
+#elif defined(_WIN32)
+ __glutOpenWin32Connection(display);
+#else
+ __glutOpenXConnection(display);
+#endif
+ if (geometry) {
+ int flags, x, y, width, height;
+
+ /* Fix bogus "{width|height} may be used before set"
+ warning */
+ width = 0;
+ height = 0;
+
+ flags = XParseGeometry(geometry, &x, &y,
+ (unsigned int *) &width, (unsigned int *) &height);
+ if (WidthValue & flags) {
+ /* Careful because X does not allow zero or negative
+ width windows */
+ if (width > 0)
+ __glutInitWidth = width;
+ }
+ if (HeightValue & flags) {
+ /* Careful because X does not allow zero or negative
+ height windows */
+ if (height > 0)
+ __glutInitHeight = height;
+ }
+ glutInitWindowSize(__glutInitWidth, __glutInitHeight);
+ if (XValue & flags) {
+ if (XNegative & flags)
+ x = DisplayWidth(__glutDisplay, __glutScreen) +
+ x - __glutSizeHints.width;
+ /* Play safe: reject negative X locations */
+ if (x >= 0)
+ __glutInitX = x;
+ }
+ if (YValue & flags) {
+ if (YNegative & flags)
+ y = DisplayHeight(__glutDisplay, __glutScreen) +
+ y - __glutSizeHints.height;
+ /* Play safe: reject negative Y locations */
+ if (y >= 0)
+ __glutInitY = y;
+ }
+ glutInitWindowPosition(__glutInitX, __glutInitY);
+ }
+ __glutInitTime(&unused);
+
+ /* check if GLUT_FPS env var is set */
+ {
+ const char *fps = getenv("GLUT_FPS");
+ if (fps) {
+ sscanf(fps, "%d", &__glutFPS);
+ if (__glutFPS <= 0)
+ __glutFPS = 5000; /* 5000 milliseconds */
+ }
+ }
+}
+
+#ifdef _WIN32
+void APIENTRY
+__glutInitWithExit(int *argcp, char **argv, void (__cdecl *exitfunc)(int))
+{
+ __glutExitFunc = exitfunc;
+ glutInit(argcp, argv);
+}
+#endif
+
+/* CENTRY */
+void GLUTAPIENTRY
+glutInitWindowPosition(int x, int y)
+{
+ __glutInitX = x;
+ __glutInitY = y;
+ if (x >= 0 && y >= 0) {
+ __glutSizeHints.x = x;
+ __glutSizeHints.y = y;
+ __glutSizeHints.flags |= USPosition;
+ } else {
+ __glutSizeHints.flags &= ~USPosition;
+ }
+}
+
+void GLUTAPIENTRY
+glutInitWindowSize(int width, int height)
+{
+ __glutInitWidth = width;
+ __glutInitHeight = height;
+ if (width > 0 && height > 0) {
+ __glutSizeHints.width = width;
+ __glutSizeHints.height = height;
+ __glutSizeHints.flags |= USSize;
+ } else {
+ __glutSizeHints.flags &= ~USSize;
+ }
+}
+
+void GLUTAPIENTRY
+glutInitDisplayMode(unsigned int mask)
+{
+ __glutDisplayMode = mask;
+}
+
+/* ENDCENTRY */