2 * DOS/DJGPP Mesa Utility Toolkit
5 * Copyright (C) 2005 Daniel Borca All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * DANIEL BORCA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 #define FREQUENCY 100 /* set this to zero to use the default timer */
34 static int timer_installed
;
36 static volatile int ticks
;
44 } ENDOFUNC(ticks_timer
)
48 static struct timeval then
;
57 return _glut_current
->xpos
;
59 return _glut_current
->ypos
;
60 case GLUT_WINDOW_WIDTH
:
61 return _glut_current
->width
;
62 case GLUT_WINDOW_HEIGHT
:
63 return _glut_current
->height
;
64 case GLUT_WINDOW_STENCIL_SIZE
:
65 return _glut_visual
.stencil
;
66 case GLUT_WINDOW_DEPTH_SIZE
:
67 return _glut_visual
.depth
;
68 case GLUT_WINDOW_RGBA
:
69 return !(_glut_default
.mode
& GLUT_INDEX
);
70 case GLUT_WINDOW_COLORMAP_SIZE
:
71 return (_glut_default
.mode
& GLUT_INDEX
) ? (256 - RESERVED_COLORS
) : 0;
72 case GLUT_SCREEN_WIDTH
:
73 return _glut_visual
.geometry
[0];
74 case GLUT_SCREEN_HEIGHT
:
75 return _glut_visual
.geometry
[1];
76 case GLUT_INIT_WINDOW_X
:
77 return _glut_default
.x
;
78 case GLUT_INIT_WINDOW_Y
:
79 return _glut_default
.y
;
80 case GLUT_INIT_WINDOW_WIDTH
:
81 return _glut_default
.width
;
82 case GLUT_INIT_WINDOW_HEIGHT
:
83 return _glut_default
.height
;
84 case GLUT_INIT_DISPLAY_MODE
:
85 return _glut_default
.mode
;
86 case GLUT_ELAPSED_TIME
:
88 if (!timer_installed
) {
89 timer_installed
= GL_TRUE
;
91 LOCKFUNC(ticks_timer
);
92 pc_install_int(ticks_timer
, NULL
, FREQUENCY
);
94 return ticks
* 1000 / FREQUENCY
;
96 if (!timer_installed
) {
97 timer_installed
= GL_TRUE
;
98 gettimeofday(&then
, NULL
);
102 gettimeofday(&now
, NULL
);
103 return (now
.tv_usec
- then
.tv_usec
) / 1000 +
104 (now
.tv_sec
- then
.tv_sec
) * 1000;
114 glutDeviceGet (GLenum type
)
117 case GLUT_HAS_KEYBOARD
:
120 return (_glut_mouse
!= 0);
121 case GLUT_NUM_MOUSE_BUTTONS
:
123 case GLUT_HAS_SPACEBALL
:
124 case GLUT_HAS_DIAL_AND_BUTTON_BOX
:
125 case GLUT_HAS_TABLET
:
127 case GLUT_NUM_SPACEBALL_BUTTONS
:
128 case GLUT_NUM_BUTTON_BOX_BUTTONS
:
130 case GLUT_NUM_TABLET_BUTTONS
:
139 glutGetModifiers (void)
142 int shifts
= pc_keyshifts();
144 if (shifts
& (KB_SHIFT_FLAG
| KB_CAPSLOCK_FLAG
)) {
145 mod
|= GLUT_ACTIVE_SHIFT
;
148 if (shifts
& KB_ALT_FLAG
) {
149 mod
|= GLUT_ACTIVE_ALT
;
152 if (shifts
& KB_CTRL_FLAG
) {
153 mod
|= GLUT_ACTIVE_CTRL
;
161 glutReportErrors (void)
163 /* reports all the OpenGL errors that happened till now */
168 * Hack alert: incomplete... what is GameMode, anyway?
171 static GLboolean game_possible
;
172 static GLboolean game_active
;
173 static GLuint game_width
;
174 static GLuint game_height
;
175 static GLuint game_bpp
;
176 static GLuint game_refresh
;
180 glutGameModeString (const char *string
)
182 if (sscanf(string
, "%ux%u:%u@%u", &game_width
, &game_height
, &game_bpp
, &game_refresh
) == 4) {
183 game_possible
= GL_TRUE
;
189 glutGameModeGet (GLenum mode
)
192 case GLUT_GAME_MODE_ACTIVE
:
194 case GLUT_GAME_MODE_POSSIBLE
:
195 return game_possible
&& !_glut_current
;
196 case GLUT_GAME_MODE_WIDTH
:
197 return game_active
? (int)game_width
: -1;
198 case GLUT_GAME_MODE_HEIGHT
:
199 return game_active
? (int)game_height
: -1;
200 case GLUT_GAME_MODE_PIXEL_DEPTH
:
201 return game_active
? (int)game_bpp
: -1;
202 case GLUT_GAME_MODE_REFRESH_RATE
:
203 return game_active
? (int)game_refresh
: -1;
211 glutEnterGameMode (void)
213 if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE
)) {
214 _glut_visual
.bpp
= game_bpp
;
215 _glut_visual
.refresh
= game_refresh
;
217 glutInitWindowSize(game_width
, game_height
);
219 if ((game
= glutCreateWindow("<game>")) > 0) {
220 game_active
= GL_TRUE
;
231 glutLeaveGameMode (void)
233 if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE
)) {
234 game_active
= GL_FALSE
;
236 glutDestroyWindow(game
);