-/*\r
- * Mesa 3-D graphics library\r
- * Version: 4.0\r
- * Copyright (C) 1995-1998 Brian Paul\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Library General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2 of the License, or (at your option) any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * Library General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Library General Public\r
- * License along with this library; if not, write to the Free\r
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
- */\r
-\r
-/*\r
- * DOS/DJGPP glut driver v0.1 for Mesa 4.0\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
-#include <signal.h>\r
-#include "GL/glut.h"\r
-#include "internal.h"\r
-\r
-\r
-static void *old_sig_int = NULL;\r
-\r
-\r
-static void signal_handler (int num)\r
-{\r
- signal(SIGINT, old_sig_int);\r
-\r
- raise(num);\r
-}\r
-\r
-\r
-void APIENTRY glutInit (int *argcp, char **argv)\r
-{\r
- /* Hack alert:\r
- only SIGINT (but not Ctrl-Break)\r
- calls the destructors and will safely clean up\r
- */\r
- old_sig_int = signal(SIGINT, signal_handler);\r
-}\r
-\r
-\r
-void APIENTRY glutInitDisplayMode (unsigned int mode)\r
-{\r
- g_display_mode = mode;\r
-\r
- pc_install_keyb();\r
- g_mouse = pc_install_mouse();\r
-}\r
-\r
-\r
-void APIENTRY glutInitWindowPosition (int x, int y)\r
-{\r
- g_xpos = x;\r
- g_ypos = y;\r
-}\r
-\r
-\r
-void APIENTRY glutInitWindowSize (int width, int height)\r
-{\r
- g_width = width;\r
- g_height = height;\r
-}\r
-\r
-\r
-void APIENTRY glutMainLoop (void)\r
-{\r
- GLboolean idle;\r
- static int old_mouse_x = 0;\r
- static int old_mouse_y = 0;\r
- static int old_mouse_b = 0;\r
-\r
- glutPostRedisplay();\r
- if (reshape_func) reshape_func(g_width, g_height);\r
- if (visibility_func) visibility_func(GLUT_VISIBLE);\r
- if (g_mouse) pc_show_mouse();\r
-\r
- while (GL_TRUE) {\r
- idle = GL_TRUE;\r
-\r
- if (g_redisplay && display_func) {\r
- idle = GL_FALSE;\r
- g_redisplay = GL_FALSE;\r
-\r
- if (g_mouse && !(g_display_mode & GLUT_DOUBLE)) pc_scare_mouse();\r
- display_func();\r
- if (g_mouse && !(g_display_mode & GLUT_DOUBLE)) pc_unscare_mouse();\r
- }\r
-\r
- if (pc_keypressed()) {\r
- int key;\r
-\r
- idle = GL_FALSE;\r
- key = pc_readkey();\r
-\r
- switch (key>>16) {\r
- case KEY_F1: if (special_func) special_func(GLUT_KEY_F1, 0, 0); break;\r
- case KEY_F2: if (special_func) special_func(GLUT_KEY_F2, 0, 0); break;\r
- case KEY_F3: if (special_func) special_func(GLUT_KEY_F3, 0, 0); break;\r
- case KEY_F4: if (special_func) special_func(GLUT_KEY_F4, 0, 0); break;\r
- case KEY_F5: if (special_func) special_func(GLUT_KEY_F5, 0, 0); break;\r
- case KEY_F6: if (special_func) special_func(GLUT_KEY_F6, 0, 0); break;\r
- case KEY_F7: if (special_func) special_func(GLUT_KEY_F7, 0, 0); break;\r
- case KEY_F8: if (special_func) special_func(GLUT_KEY_F8, 0, 0); break;\r
- case KEY_F9: if (special_func) special_func(GLUT_KEY_F9, 0, 0); break;\r
- case KEY_F10: if (special_func) special_func(GLUT_KEY_F10, 0, 0); break;\r
- case KEY_F11: if (special_func) special_func(GLUT_KEY_F11, 0, 0); break;\r
- case KEY_F12: if (special_func) special_func(GLUT_KEY_F12, 0, 0); break;\r
- case KEY_LEFT: if (special_func) special_func(GLUT_KEY_LEFT, 0, 0); break;\r
- case KEY_UP: if (special_func) special_func(GLUT_KEY_UP, 0, 0); break;\r
- case KEY_RIGHT: if (special_func) special_func(GLUT_KEY_RIGHT, 0, 0); break;\r
- case KEY_DOWN: if (special_func) special_func(GLUT_KEY_DOWN, 0, 0); break;\r
- case KEY_PGUP: if (special_func) special_func(GLUT_KEY_PAGE_UP, 0, 0); break;\r
- case KEY_PGDN: if (special_func) special_func(GLUT_KEY_PAGE_DOWN, 0, 0); break;\r
- case KEY_HOME: if (special_func) special_func(GLUT_KEY_HOME, 0, 0); break;\r
- case KEY_END: if (special_func) special_func(GLUT_KEY_END, 0, 0); break;\r
- case KEY_INSERT: if (special_func) special_func(GLUT_KEY_INSERT, 0, 0); break;\r
- default: if (keyboard_func) keyboard_func(key & 0xFF, 0, 0);\r
- }\r
- }\r
-\r
- if (g_mouse && motion_func && ((pc_mouse_x != old_mouse_x) || (pc_mouse_y != old_mouse_y))) {\r
- idle = GL_FALSE;\r
- old_mouse_x = pc_mouse_x;\r
- old_mouse_y = pc_mouse_y;\r
-\r
- motion_func(old_mouse_x, old_mouse_y);\r
- }\r
-\r
- if (g_mouse && mouse_func && (pc_mouse_b != old_mouse_b)) {\r
- int new_mouse_b = pc_mouse_b;\r
-\r
- if ((old_mouse_b & 1) && !(new_mouse_b & 1))\r
- mouse_func(GLUT_LEFT_BUTTON, GLUT_UP, pc_mouse_x, pc_mouse_y);\r
- else if (!(old_mouse_b & 1) && (new_mouse_b & 1))\r
- mouse_func(GLUT_LEFT_BUTTON, GLUT_DOWN, pc_mouse_x, pc_mouse_y);\r
-\r
- if ((old_mouse_b & 2) && !(new_mouse_b & 2))\r
- mouse_func(GLUT_RIGHT_BUTTON, GLUT_UP, pc_mouse_x, pc_mouse_y);\r
- else if (!(old_mouse_b & 2) && (new_mouse_b & 2))\r
- mouse_func(GLUT_RIGHT_BUTTON, GLUT_DOWN, pc_mouse_x, pc_mouse_y);\r
-\r
- if ((old_mouse_b & 4) && !(new_mouse_b & 4))\r
- mouse_func(GLUT_MIDDLE_BUTTON, GLUT_UP, pc_mouse_x, pc_mouse_y);\r
- else if (!(old_mouse_b & 3) && (new_mouse_b & 4))\r
- mouse_func(GLUT_MIDDLE_BUTTON, GLUT_DOWN, pc_mouse_x, pc_mouse_y);\r
-\r
- idle = GL_FALSE;\r
- old_mouse_b = new_mouse_b;\r
- }\r
-\r
- if (idle && idle_func)\r
- idle_func();\r
- }\r
-}\r
+/*
+ * DOS/DJGPP Mesa Utility Toolkit
+ * Version: 1.0
+ *
+ * Copyright (C) 2005 Daniel Borca All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * DANIEL BORCA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "internal.h"
+
+
+char *__glutProgramName = NULL;
+
+GLUTvisual _glut_visual = {
+ 16, 8, 16, 8, 16, /* bpp, alpha, depth, stencil, accum */
+
+ { 0, 0 }, 0, /* geometry */
+
+ 0 /* flags */
+};
+
+GLUTdefault _glut_default = {
+ 0, 0, /* glutInitWindowPosition */
+ 300, 300, /* glutInitWindowSize */
+ 0 /* glutInitDisplayMode */
+};
+
+GLuint _glut_fps = 0;
+
+static char *init_string;
+
+
+void
+_glut_fatal (char *format,...)
+{
+ va_list args;
+
+ va_start(args, format);
+ fprintf(stderr, "GLUT: Fatal Error in %s: ",
+ __glutProgramName ? __glutProgramName : "(unamed)");
+ vfprintf(stderr, format, args);
+ va_end(args);
+ putc('\n', stderr);
+ exit(1);
+}
+
+
+/* strdup is actually not a standard ANSI C or POSIX routine
+ * so implement a private one for GLUT.
+ */
+static char *
+_glut_strdup (const char *string)
+{
+ if (string != NULL) {
+ int len = strlen(string) + 1;
+ char *p = malloc(len);
+ if (p != NULL) {
+ return strcpy(p, string);
+ }
+ }
+ return NULL;
+}
+
+
+void APIENTRY
+glutInit (int *argc, char **argv)
+{
+ char *str;
+ const char *env;
+
+ if ((env = getenv("DMESA_GLUT_BPP")) != NULL) {
+ _glut_visual.bpp = atoi(env);
+ }
+ if ((env = getenv("DMESA_GLUT_ALPHA")) != NULL) {
+ _glut_visual.alpha = atoi(env);
+ }
+ if ((env = getenv("DMESA_GLUT_DEPTH")) != NULL) {
+ _glut_visual.depth = atoi(env);
+ }
+ if ((env = getenv("DMESA_GLUT_STENCIL")) != NULL) {
+ _glut_visual.stencil = atoi(env);
+ }
+ if ((env = getenv("DMESA_GLUT_ACCUM")) != NULL) {
+ _glut_visual.accum = atoi(env);
+ }
+ if ((env = getenv("DMESA_GLUT_REFRESH")) != NULL) {
+ _glut_visual.refresh = atoi(env);
+ }
+
+ /* Determine program name. */
+ str = strrchr(argv[0], '/');
+ if (str == NULL) {
+ str = argv[0];
+ } else {
+ str++;
+ }
+ __glutProgramName = _glut_strdup(str);
+
+ /* check if GLUT_FPS env var is set */
+ if ((env = getenv("GLUT_FPS")) != NULL) {
+ if ((_glut_fps = atoi(env)) <= 0) {
+ _glut_fps = 5000; /* 5000 milliseconds */
+ }
+ }
+
+ /* Initialize timer */
+ glutGet(GLUT_ELAPSED_TIME);
+}
+
+
+void APIENTRY
+glutInitDisplayMode (unsigned int mode)
+{
+ _glut_default.mode = mode;
+}
+
+
+void APIENTRY
+glutInitWindowPosition (int x, int y)
+{
+ _glut_default.x = x;
+ _glut_default.y = y;
+}
+
+
+void APIENTRY
+glutInitWindowSize (int width, int height)
+{
+ _glut_default.width = width;
+ _glut_default.height = height;
+}
+
+
+void APIENTRY
+glutInitDisplayString (const char *string)
+{
+ init_string = _glut_strdup(string);
+}
+
+
+void APIENTRY
+glutSetOption (GLenum pname, int value)
+{
+ switch (pname) {
+ case GLUT_INIT_WINDOW_X:
+ _glut_default.x = value;
+ break;
+ case GLUT_INIT_WINDOW_Y:
+ _glut_default.y = value;
+ break;
+ }
+}
+
+
+void APIENTRY
+glutForceJoystickFunc (void)
+{
+}
+
+
+void APIENTRY
+glutIgnoreKeyRepeat (int ignore)
+{
+}
+
+
+void APIENTRY
+glutSetKeyRepeat (int repeatMode)
+{
+}
+
+
+void APIENTRY
+glutVideoPan (int x, int y, int w, int h)
+{
+}
+
+
+int APIENTRY
+glutVideoResizeGet( GLenum eWhat )
+{
+ return 0;
+}
+
+
+void APIENTRY
+glutSetupVideoResizing (void)
+{
+}
+
+
+void APIENTRY
+glutStopVideoResizing (void)
+{
+}
+
+
+void APIENTRY
+glutVideoResize (int x, int y, int w, int h)
+{
+}