DOS updates for new tree (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
23 *
24 * Copyright (C) 2002 - Borca Daniel
25 * Email : dborca@yahoo.com
26 * Web : http://www.geocities.com/dborca
27 */
28
29
30 #include <string.h>
31
32 #include "glutint.h"
33
34
35
36 GLboolean g_redisplay = GL_FALSE;
37
38 GLuint g_bpp = DEFAULT_BPP;
39 GLuint g_refresh = 0;
40 GLuint g_screen_w, g_screen_h;
41 GLint g_driver_caps;
42
43 GLuint g_fps = 0;
44
45 GLuint g_display_mode = 0;
46 int g_init_x = 0, g_init_y = 0;
47 GLuint g_init_w = DEFAULT_WIDTH, g_init_h = DEFAULT_HEIGHT;
48
49 char *__glutProgramName = NULL;
50
51
52
53 void APIENTRY glutInit (int *argc, char **argv)
54 {
55 char *str;
56 const char *env;
57
58 if ((env = getenv("DMESA_GLUT_BPP")) != NULL) {
59 g_bpp = atoi(env);
60 }
61 if ((env = getenv("DMESA_GLUT_REFRESH")) != NULL) {
62 g_refresh = atoi(env);
63 }
64
65 /* Determine program name. */
66 str = strrchr(argv[0], '/');
67 if (str == NULL) {
68 str = argv[0];
69 } else {
70 str++;
71 }
72 __glutProgramName = __glutStrdup(str);
73
74 /* check if GLUT_FPS env var is set */
75 if ((env = getenv("GLUT_FPS")) != NULL) {
76 if ((g_fps = atoi(env)) <= 0) {
77 g_fps = 5000; /* 5000 milliseconds */
78 }
79 }
80
81 /* Initialize timer */
82 glutGet(GLUT_ELAPSED_TIME);
83 }
84
85
86
87 void APIENTRY glutInitDisplayMode (unsigned int mode)
88 {
89 g_display_mode = mode;
90 }
91
92
93
94 void APIENTRY glutInitWindowPosition (int x, int y)
95 {
96 g_init_x = x;
97 g_init_y = y;
98 }
99
100
101
102 void APIENTRY glutInitWindowSize (int width, int height)
103 {
104 g_init_w = width;
105 g_init_h = height;
106 }
107
108
109
110 void APIENTRY glutMainLoop (void)
111 {
112 GLboolean idle;
113 static int old_mouse_x = 0;
114 static int old_mouse_y = 0;
115 static int old_mouse_b = 0;
116
117 {
118 GLint screen_size[2];
119 DMesaGetIntegerv(DMESA_GET_SCREEN_SIZE, screen_size);
120 g_screen_w = screen_size[0];
121 g_screen_h = screen_size[1];
122 DMesaGetIntegerv(DMESA_GET_DRIVER_CAPS, &g_driver_caps);
123 }
124
125 pc_install_keyb();
126 __glutInitMouse();
127
128 glutPostRedisplay();
129 if (g_curwin->reshape) {
130 g_curwin->reshape(g_curwin->width, g_curwin->height);
131 }
132 if (g_curwin->visibility) {
133 g_curwin->visibility(GLUT_VISIBLE);
134 }
135
136 while (GL_TRUE) {
137 idle = GL_TRUE;
138
139 if (g_redisplay && g_curwin->display) {
140 idle = GL_FALSE;
141 g_redisplay = GL_FALSE;
142
143 if (g_curwin->show_mouse && !(g_display_mode & GLUT_DOUBLE)) {
144 /* XXX scare mouse */
145 g_curwin->display();
146 /* XXX unscare mouse */
147 } else {
148 g_curwin->display();
149 }
150 }
151
152 if (g_mouse) {
153 int mouse_x;
154 int mouse_y;
155 int mouse_z;
156 int mouse_b;
157
158 /* query mouse */
159 mouse_b = pc_query_mouse(&mouse_x, &mouse_y, &mouse_z);
160
161 /* relative to window coordinates */
162 g_mouse_x = mouse_x - g_curwin->xpos;
163 g_mouse_y = mouse_y - g_curwin->ypos;
164
165 /* mouse was moved? */
166 if ((mouse_x != old_mouse_x) || (mouse_y != old_mouse_y)) {
167 idle = GL_FALSE;
168 old_mouse_x = mouse_x;
169 old_mouse_y = mouse_y;
170
171 if (mouse_b) {
172 /* any button pressed */
173 if (g_curwin->motion) {
174 g_curwin->motion(g_mouse_x, g_mouse_y);
175 }
176 } else {
177 /* no button pressed */
178 if (g_curwin->passive) {
179 g_curwin->passive(g_mouse_x, g_mouse_y);
180 }
181 }
182 }
183
184 /* button state changed? */
185 if (mouse_b != old_mouse_b) {
186 GLUTmouseCB mouse_func;
187
188 if ((mouse_func = g_curwin->mouse)) {
189 if ((old_mouse_b & 1) && !(mouse_b & 1))
190 mouse_func(GLUT_LEFT_BUTTON, GLUT_UP, g_mouse_x, g_mouse_y);
191 else if (!(old_mouse_b & 1) && (mouse_b & 1))
192 mouse_func(GLUT_LEFT_BUTTON, GLUT_DOWN, g_mouse_x, g_mouse_y);
193
194 if ((old_mouse_b & 2) && !(mouse_b & 2))
195 mouse_func(GLUT_RIGHT_BUTTON, GLUT_UP, g_mouse_x, g_mouse_y);
196 else if (!(old_mouse_b & 2) && (mouse_b & 2))
197 mouse_func(GLUT_RIGHT_BUTTON, GLUT_DOWN, g_mouse_x, g_mouse_y);
198
199 if ((old_mouse_b & 4) && !(mouse_b & 4))
200 mouse_func(GLUT_MIDDLE_BUTTON, GLUT_UP, g_mouse_x, g_mouse_y);
201 else if (!(old_mouse_b & 3) && (mouse_b & 4))
202 mouse_func(GLUT_MIDDLE_BUTTON, GLUT_DOWN, g_mouse_x, g_mouse_y);
203 }
204
205 idle = GL_FALSE;
206 old_mouse_b = mouse_b;
207 }
208 }
209
210 if (pc_keypressed()) {
211 int key;
212 int glut_key;
213
214 idle = GL_FALSE;
215 key = pc_readkey();
216
217 switch (key>>16) {
218 case KEY_F1: glut_key = GLUT_KEY_F1; goto special;
219 case KEY_F2: glut_key = GLUT_KEY_F2; goto special;
220 case KEY_F3: glut_key = GLUT_KEY_F3; goto special;
221 case KEY_F4: glut_key = GLUT_KEY_F4; goto special;
222 case KEY_F5: glut_key = GLUT_KEY_F5; goto special;
223 case KEY_F6: glut_key = GLUT_KEY_F6; goto special;
224 case KEY_F7: glut_key = GLUT_KEY_F7; goto special;
225 case KEY_F8: glut_key = GLUT_KEY_F8; goto special;
226 case KEY_F9: glut_key = GLUT_KEY_F9; goto special;
227 case KEY_F10: glut_key = GLUT_KEY_F10; goto special;
228 case KEY_F11: glut_key = GLUT_KEY_F11; goto special;
229 case KEY_F12: glut_key = GLUT_KEY_F12; goto special;
230 case KEY_LEFT: glut_key = GLUT_KEY_LEFT; goto special;
231 case KEY_UP: glut_key = GLUT_KEY_UP; goto special;
232 case KEY_RIGHT: glut_key = GLUT_KEY_RIGHT; goto special;
233 case KEY_DOWN: glut_key = GLUT_KEY_DOWN; goto special;
234 case KEY_PGUP: glut_key = GLUT_KEY_PAGE_UP; goto special;
235 case KEY_PGDN: glut_key = GLUT_KEY_PAGE_DOWN; goto special;
236 case KEY_HOME: glut_key = GLUT_KEY_HOME; goto special;
237 case KEY_END: glut_key = GLUT_KEY_END; goto special;
238 case KEY_INSERT: glut_key = GLUT_KEY_INSERT; goto special;
239 special:
240 if (g_curwin->special) {
241 g_curwin->special(glut_key, g_mouse_x, g_mouse_y);
242 }
243 break;
244 default:
245 if (g_curwin->keyboard) {
246 g_curwin->keyboard(key & 0xFF, g_mouse_x, g_mouse_y);
247 }
248 }
249 }
250
251 if (idle && g_idle_func)
252 g_idle_func();
253 }
254 }