2 * Mesa 3-D graphics library
4 * Copyright (C) 1995-1998 Brian Paul
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.
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.
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.
22 * DOS/DJGPP glut driver v1.3 for Mesa 5.0
24 * Copyright (C) 2002 - Borca Daniel
25 * Email : dborca@yahoo.com
26 * Web : http://www.geocities.com/dborca
36 GLboolean g_redisplay
= GL_FALSE
;
38 GLuint g_bpp
= DEFAULT_BPP
;
40 GLuint g_screen_w
, g_screen_h
;
42 GLuint g_display_mode
= 0;
43 int g_init_x
= 0, g_init_y
= 0;
44 GLuint g_init_w
= DEFAULT_WIDTH
, g_init_h
= DEFAULT_HEIGHT
;
46 char *__glutProgramName
= NULL
;
50 void APIENTRY
glutInit (int *argc
, char **argv
)
55 if ((env
= getenv("DMESA_GLUT_BPP")) != NULL
) {
58 if ((env
= getenv("DMESA_GLUT_REFRESH")) != NULL
) {
59 g_refresh
= atoi(env
);
62 /* Determine program name. */
63 str
= strrchr(argv
[0], '/');
69 __glutProgramName
= __glutStrdup(str
);
71 /* Initialize timer */
72 glutGet(GLUT_ELAPSED_TIME
);
77 void APIENTRY
glutInitDisplayMode (unsigned int mode
)
79 g_display_mode
= mode
;
84 void APIENTRY
glutInitWindowPosition (int x
, int y
)
92 void APIENTRY
glutInitWindowSize (int width
, int height
)
100 void APIENTRY
glutMainLoop (void)
103 static int old_mouse_x
= 0;
104 static int old_mouse_y
= 0;
105 static int old_mouse_b
= 0;
108 GLint screen_size
[2];
109 DMesaGetIntegerv(DMESA_SCREEN_SIZE
, screen_size
);
110 g_screen_w
= screen_size
[0];
111 g_screen_h
= screen_size
[1];
118 if (g_curwin
->reshape
) {
119 g_curwin
->reshape(g_curwin
->width
, g_curwin
->height
);
121 if (g_curwin
->visibility
) {
122 g_curwin
->visibility(GLUT_VISIBLE
);
128 if (g_redisplay
&& g_curwin
->display
) {
130 g_redisplay
= GL_FALSE
;
132 if (g_curwin
->show_mouse
&& !(g_display_mode
& GLUT_DOUBLE
)) {
133 /* XXX scare mouse */
135 /* XXX unscare mouse */
147 mouse_b
= pc_query_mouse(&mouse_x
, &mouse_y
);
149 /* relative to window coordinates */
150 g_mouse_x
= mouse_x
- g_curwin
->xpos
;
151 g_mouse_y
= mouse_y
- g_curwin
->ypos
;
153 /* mouse was moved? */
154 if ((mouse_x
!= old_mouse_x
) || (mouse_y
!= old_mouse_y
)) {
156 old_mouse_x
= mouse_x
;
157 old_mouse_y
= mouse_y
;
160 /* any button pressed */
161 if (g_curwin
->motion
) {
162 g_curwin
->motion(g_mouse_x
, g_mouse_y
);
165 /* no button pressed */
166 if (g_curwin
->passive
) {
167 g_curwin
->passive(g_mouse_x
, g_mouse_y
);
172 /* button state changed? */
173 if (mouse_b
!= old_mouse_b
) {
174 GLUTmouseCB mouse_func
;
176 if ((mouse_func
= g_curwin
->mouse
)) {
177 if ((old_mouse_b
& 1) && !(mouse_b
& 1))
178 mouse_func(GLUT_LEFT_BUTTON
, GLUT_UP
, g_mouse_x
, g_mouse_y
);
179 else if (!(old_mouse_b
& 1) && (mouse_b
& 1))
180 mouse_func(GLUT_LEFT_BUTTON
, GLUT_DOWN
, g_mouse_x
, g_mouse_y
);
182 if ((old_mouse_b
& 2) && !(mouse_b
& 2))
183 mouse_func(GLUT_RIGHT_BUTTON
, GLUT_UP
, g_mouse_x
, g_mouse_y
);
184 else if (!(old_mouse_b
& 2) && (mouse_b
& 2))
185 mouse_func(GLUT_RIGHT_BUTTON
, GLUT_DOWN
, g_mouse_x
, g_mouse_y
);
187 if ((old_mouse_b
& 4) && !(mouse_b
& 4))
188 mouse_func(GLUT_MIDDLE_BUTTON
, GLUT_UP
, g_mouse_x
, g_mouse_y
);
189 else if (!(old_mouse_b
& 3) && (mouse_b
& 4))
190 mouse_func(GLUT_MIDDLE_BUTTON
, GLUT_DOWN
, g_mouse_x
, g_mouse_y
);
194 old_mouse_b
= mouse_b
;
198 if (pc_keypressed()) {
206 case KEY_F1
: glut_key
= GLUT_KEY_F1
; goto special
;
207 case KEY_F2
: glut_key
= GLUT_KEY_F2
; goto special
;
208 case KEY_F3
: glut_key
= GLUT_KEY_F3
; goto special
;
209 case KEY_F4
: glut_key
= GLUT_KEY_F4
; goto special
;
210 case KEY_F5
: glut_key
= GLUT_KEY_F5
; goto special
;
211 case KEY_F6
: glut_key
= GLUT_KEY_F6
; goto special
;
212 case KEY_F7
: glut_key
= GLUT_KEY_F7
; goto special
;
213 case KEY_F8
: glut_key
= GLUT_KEY_F8
; goto special
;
214 case KEY_F9
: glut_key
= GLUT_KEY_F9
; goto special
;
215 case KEY_F10
: glut_key
= GLUT_KEY_F10
; goto special
;
216 case KEY_F11
: glut_key
= GLUT_KEY_F11
; goto special
;
217 case KEY_F12
: glut_key
= GLUT_KEY_F12
; goto special
;
218 case KEY_LEFT
: glut_key
= GLUT_KEY_LEFT
; goto special
;
219 case KEY_UP
: glut_key
= GLUT_KEY_UP
; goto special
;
220 case KEY_RIGHT
: glut_key
= GLUT_KEY_RIGHT
; goto special
;
221 case KEY_DOWN
: glut_key
= GLUT_KEY_DOWN
; goto special
;
222 case KEY_PGUP
: glut_key
= GLUT_KEY_PAGE_UP
; goto special
;
223 case KEY_PGDN
: glut_key
= GLUT_KEY_PAGE_DOWN
; goto special
;
224 case KEY_HOME
: glut_key
= GLUT_KEY_HOME
; goto special
;
225 case KEY_END
: glut_key
= GLUT_KEY_END
; goto special
;
226 case KEY_INSERT
: glut_key
= GLUT_KEY_INSERT
; goto special
;
228 if (g_curwin
->special
) {
229 g_curwin
->special(glut_key
, g_mouse_x
, g_mouse_y
);
233 if (g_curwin
->keyboard
) {
234 g_curwin
->keyboard(key
& 0xFF, g_mouse_x
, g_mouse_y
);
239 if (idle
&& g_idle_func
)