DOS updates from Daniel Borca.
[mesa.git] / src / glut / dos / init.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 4.0
4 * Copyright (C) 1995-1998 Brian Paul
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 /*
22 * DOS/DJGPP glut driver v1.3 for Mesa 5.0
23 *
24 * Copyright (C) 2002 - Borca Daniel
25 * Email : dborca@yahoo.com
26 * Web : http://www.geocities.com/dborca
27 */
28
29
30 #include "GL/glut.h"
31 #include "internal.h"
32
33
34 void APIENTRY glutInit (int *argcp, char **argv)
35 {
36 const char *env;
37
38 if ((env = getenv("DMESA_GLUT_BPP")) != NULL) {
39 g_bpp = atoi(env);
40 }
41 if ((env = getenv("DMESA_GLUT_REFRESH")) != NULL) {
42 g_refresh = atoi(env);
43 }
44
45 glutGet(GLUT_ELAPSED_TIME);
46 }
47
48
49 void APIENTRY glutInitDisplayMode (unsigned int mode)
50 {
51 g_display_mode = mode;
52
53 pc_install_keyb();
54 g_mouse = pc_install_mouse();
55 }
56
57
58 void APIENTRY glutInitWindowPosition (int x, int y)
59 {
60 g_xpos = x;
61 g_ypos = y;
62 }
63
64
65 void APIENTRY glutInitWindowSize (int width, int height)
66 {
67 g_width = width;
68 g_height = height;
69 }
70
71
72 void APIENTRY glutMainLoop (void)
73 {
74 GLboolean idle;
75 static int old_mouse_x = 0;
76 static int old_mouse_y = 0;
77 static int old_mouse_b = 0;
78
79 glutPostRedisplay();
80 if (reshape_func) reshape_func(g_width, g_height);
81 if (visibility_func) visibility_func(GLUT_VISIBLE);
82 if (g_mouse) pc_show_mouse();
83
84 while (GL_TRUE) {
85 idle = GL_TRUE;
86
87 if (g_redisplay && display_func) {
88 idle = GL_FALSE;
89 g_redisplay = GL_FALSE;
90
91 if (g_mouse && !(g_display_mode & GLUT_DOUBLE)) pc_scare_mouse();
92 display_func();
93 if (g_mouse && !(g_display_mode & GLUT_DOUBLE)) pc_unscare_mouse();
94 }
95
96 if (pc_keypressed()) {
97 int key;
98
99 idle = GL_FALSE;
100 key = pc_readkey();
101
102 switch (key>>16) {
103 case KEY_F1: if (special_func) special_func(GLUT_KEY_F1, 0, 0); break;
104 case KEY_F2: if (special_func) special_func(GLUT_KEY_F2, 0, 0); break;
105 case KEY_F3: if (special_func) special_func(GLUT_KEY_F3, 0, 0); break;
106 case KEY_F4: if (special_func) special_func(GLUT_KEY_F4, 0, 0); break;
107 case KEY_F5: if (special_func) special_func(GLUT_KEY_F5, 0, 0); break;
108 case KEY_F6: if (special_func) special_func(GLUT_KEY_F6, 0, 0); break;
109 case KEY_F7: if (special_func) special_func(GLUT_KEY_F7, 0, 0); break;
110 case KEY_F8: if (special_func) special_func(GLUT_KEY_F8, 0, 0); break;
111 case KEY_F9: if (special_func) special_func(GLUT_KEY_F9, 0, 0); break;
112 case KEY_F10: if (special_func) special_func(GLUT_KEY_F10, 0, 0); break;
113 case KEY_F11: if (special_func) special_func(GLUT_KEY_F11, 0, 0); break;
114 case KEY_F12: if (special_func) special_func(GLUT_KEY_F12, 0, 0); break;
115 case KEY_LEFT: if (special_func) special_func(GLUT_KEY_LEFT, 0, 0); break;
116 case KEY_UP: if (special_func) special_func(GLUT_KEY_UP, 0, 0); break;
117 case KEY_RIGHT: if (special_func) special_func(GLUT_KEY_RIGHT, 0, 0); break;
118 case KEY_DOWN: if (special_func) special_func(GLUT_KEY_DOWN, 0, 0); break;
119 case KEY_PGUP: if (special_func) special_func(GLUT_KEY_PAGE_UP, 0, 0); break;
120 case KEY_PGDN: if (special_func) special_func(GLUT_KEY_PAGE_DOWN, 0, 0); break;
121 case KEY_HOME: if (special_func) special_func(GLUT_KEY_HOME, 0, 0); break;
122 case KEY_END: if (special_func) special_func(GLUT_KEY_END, 0, 0); break;
123 case KEY_INSERT: if (special_func) special_func(GLUT_KEY_INSERT, 0, 0); break;
124 default: if (keyboard_func) keyboard_func(key & 0xFF, 0, 0);
125 }
126 }
127
128 if (g_mouse) {
129 int mouse_x;
130 int mouse_y;
131 int mouse_b;
132
133 mouse_b = pc_query_mouse(&mouse_x, &mouse_y);
134
135 if (motion_func && ((mouse_x != old_mouse_x) || (mouse_y != old_mouse_y))) {
136 idle = GL_FALSE;
137 old_mouse_x = mouse_x;
138 old_mouse_y = mouse_y;
139
140 motion_func(old_mouse_x, old_mouse_y);
141 }
142
143 if (mouse_func && (mouse_b != old_mouse_b)) {
144 int new_mouse_b = mouse_b;
145
146 if ((old_mouse_b & 1) && !(new_mouse_b & 1))
147 mouse_func(GLUT_LEFT_BUTTON, GLUT_UP, mouse_x, mouse_y);
148 else if (!(old_mouse_b & 1) && (new_mouse_b & 1))
149 mouse_func(GLUT_LEFT_BUTTON, GLUT_DOWN, mouse_x, mouse_y);
150
151 if ((old_mouse_b & 2) && !(new_mouse_b & 2))
152 mouse_func(GLUT_RIGHT_BUTTON, GLUT_UP, mouse_x, mouse_y);
153 else if (!(old_mouse_b & 2) && (new_mouse_b & 2))
154 mouse_func(GLUT_RIGHT_BUTTON, GLUT_DOWN, mouse_x, mouse_y);
155
156 if ((old_mouse_b & 4) && !(new_mouse_b & 4))
157 mouse_func(GLUT_MIDDLE_BUTTON, GLUT_UP, mouse_x, mouse_y);
158 else if (!(old_mouse_b & 3) && (new_mouse_b & 4))
159 mouse_func(GLUT_MIDDLE_BUTTON, GLUT_DOWN, mouse_x, mouse_y);
160
161 idle = GL_FALSE;
162 old_mouse_b = new_mouse_b;
163 }
164 }
165
166 if (idle && idle_func)
167 idle_func();
168 }
169 }