DOS and glide driver updates from Daniel Borca
[mesa.git] / src / glut / dos / state.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 3.4
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.4 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 "glutint.h"
31
32
33
34 #define FREQUENCY 100
35
36
37
38 static int timer_installed;
39 static volatile int ticks;
40
41
42
43 static void ticks_timer (void *p)
44 {
45 (void)p;
46 ticks++;
47 } ENDOFUNC(ticks_timer)
48
49
50
51 int APIENTRY glutGet (GLenum type)
52 {
53 switch (type) {
54 case GLUT_WINDOW_X:
55 return g_curwin->xpos;
56 case GLUT_WINDOW_Y:
57 return g_curwin->ypos;
58 case GLUT_WINDOW_WIDTH:
59 return g_curwin->width;
60 case GLUT_WINDOW_HEIGHT:
61 return g_curwin->height;
62 case GLUT_WINDOW_STENCIL_SIZE:
63 return g_stencil;
64 case GLUT_WINDOW_DEPTH_SIZE:
65 return g_depth;
66 case GLUT_WINDOW_RGBA:
67 return !(g_display_mode & GLUT_INDEX);
68 case GLUT_WINDOW_COLORMAP_SIZE:
69 return (g_display_mode & GLUT_INDEX) ? (256 - RESERVED_COLORS) : 0;
70 case GLUT_SCREEN_WIDTH:
71 return g_screen_w;
72 case GLUT_SCREEN_HEIGHT:
73 return g_screen_h;
74 case GLUT_INIT_WINDOW_X:
75 return g_init_x;
76 case GLUT_INIT_WINDOW_Y:
77 return g_init_y;
78 case GLUT_INIT_WINDOW_WIDTH:
79 return g_init_w;
80 case GLUT_INIT_WINDOW_HEIGHT:
81 return g_init_h;
82 case GLUT_INIT_DISPLAY_MODE:
83 return g_display_mode;
84 case GLUT_ELAPSED_TIME:
85 if (!timer_installed) {
86 timer_installed = GL_TRUE;
87 LOCKDATA(ticks);
88 LOCKFUNC(ticks_timer);
89 pc_install_int(ticks_timer, NULL, FREQUENCY);
90 }
91 return ticks*1000/FREQUENCY;
92 default:
93 return -1;
94 }
95 }
96
97
98
99 int APIENTRY glutDeviceGet (GLenum type)
100 {
101 switch (type) {
102 case GLUT_HAS_KEYBOARD:
103 return GL_TRUE;
104 case GLUT_HAS_MOUSE:
105 return (g_mouse != 0);
106 case GLUT_NUM_MOUSE_BUTTONS:
107 return g_mouse;
108 case GLUT_HAS_SPACEBALL:
109 case GLUT_HAS_DIAL_AND_BUTTON_BOX:
110 case GLUT_HAS_TABLET:
111 return GL_FALSE;
112 case GLUT_NUM_SPACEBALL_BUTTONS:
113 case GLUT_NUM_BUTTON_BOX_BUTTONS:
114 case GLUT_NUM_DIALS:
115 case GLUT_NUM_TABLET_BUTTONS:
116 return 0;
117 default:
118 return -1;
119 }
120 }
121
122
123
124 int APIENTRY glutGetModifiers (void)
125 {
126 int mod = 0;
127 int shifts = pc_keyshifts();
128
129 if (shifts & (KB_SHIFT_FLAG | KB_CAPSLOCK_FLAG)) {
130 mod |= GLUT_ACTIVE_SHIFT;
131 }
132
133 if (shifts & KB_ALT_FLAG) {
134 mod |= GLUT_ACTIVE_ALT;
135 }
136
137 if (shifts & KB_CTRL_FLAG) {
138 mod |= GLUT_ACTIVE_CTRL;
139 }
140
141 return mod;
142 }