summaryrefslogtreecommitdiffstats
path: root/src/glut/dos/init.c
blob: 0f848f6f360d2066cc51796667dd32cee3a3537b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/*
 * Mesa 3-D graphics library
 * Version:  4.0
 * Copyright (C) 1995-1998  Brian Paul
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
 * DOS/DJGPP glut driver v1.3 for Mesa 5.0
 *
 *  Copyright (C) 2002 - Borca Daniel
 *  Email : dborca@yahoo.com
 *  Web   : http://www.geocities.com/dborca
 */


#include <string.h>

#include "glutint.h"



GLboolean g_redisplay = GL_FALSE;

GLuint g_bpp = DEFAULT_BPP;
GLuint g_refresh = 0;
GLuint g_screen_w, g_screen_h;

GLuint g_display_mode = 0;
int g_init_x = 0, g_init_y = 0;
GLuint g_init_w = DEFAULT_WIDTH, g_init_h = DEFAULT_HEIGHT;

char *__glutProgramName = NULL;



void APIENTRY glutInit (int *argc, char **argv)
{
 char *str;
 const char *env;

 if ((env = getenv("DMESA_GLUT_BPP")) != NULL) {
    g_bpp = atoi(env);
 }
 if ((env = getenv("DMESA_GLUT_REFRESH")) != NULL) {
    g_refresh = atoi(env);
 }

 /* Determine program name. */
 str = strrchr(argv[0], '/');
 if (str == NULL) {
    str = argv[0];
 } else {
    str++;
 }
 __glutProgramName = __glutStrdup(str);

 /* Initialize timer */
 glutGet(GLUT_ELAPSED_TIME);
}



void APIENTRY glutInitDisplayMode (unsigned int mode)
{
 g_display_mode = mode;
}



void APIENTRY glutInitWindowPosition (int x, int y)
{
 g_init_x = x;
 g_init_y = y;
}



void APIENTRY glutInitWindowSize (int width, int height)
{
 g_init_w = width;
 g_init_h = height;
}



void APIENTRY glutMainLoop (void)
{
 GLboolean idle;
 static int old_mouse_x = 0;
 static int old_mouse_y = 0;
 static int old_mouse_b = 0;

 {
  GLint screen_size[2];
  DMesaGetIntegerv(DMESA_SCREEN_SIZE, screen_size);
  g_screen_w = screen_size[0];
  g_screen_h = screen_size[1];
 }

 pc_install_keyb();
 __glutInitMouse();

 glutPostRedisplay();
 if (g_curwin->reshape) {
    g_curwin->reshape(g_curwin->width, g_curwin->height);
 }
 if (g_curwin->visibility) {
    g_curwin->visibility(GLUT_VISIBLE);
 }

 while (GL_TRUE) {
       idle = GL_TRUE;

       if (g_redisplay && g_curwin->display) {
          idle        = GL_FALSE;
          g_redisplay = GL_FALSE;

          if (g_curwin->show_mouse && !(g_display_mode & GLUT_DOUBLE)) {
             /* XXX scare mouse */
             g_curwin->display();
             /* XXX unscare mouse */
          } else {
             g_curwin->display();
          }
       }

       if (g_mouse) {
          int mouse_x;
          int mouse_y;
          int mouse_b;

          /* query mouse */
          mouse_b = pc_query_mouse(&mouse_x, &mouse_y);

          /* relative to window coordinates */
          g_mouse_x = mouse_x - g_curwin->xpos;
          g_mouse_y = mouse_y - g_curwin->ypos;

          /* mouse was moved? */
          if ((mouse_x != old_mouse_x) || (mouse_y != old_mouse_y)) {
             idle        = GL_FALSE;
             old_mouse_x = mouse_x;
             old_mouse_y = mouse_y;

             if (mouse_b) {
                /* any button pressed */
                if (g_curwin->motion) {
                   g_curwin->motion(g_mouse_x, g_mouse_y);
                }
             } else {
                /* no button pressed */
                if (g_curwin->passive) {
                   g_curwin->passive(g_mouse_x, g_mouse_y);
                }
             }
          }

          /* button state changed? */
          if (mouse_b != old_mouse_b) {
             GLUTmouseCB mouse_func;

             if ((mouse_func = g_curwin->mouse)) {
                if ((old_mouse_b & 1) && !(mouse_b & 1))
                   mouse_func(GLUT_LEFT_BUTTON, GLUT_UP,     g_mouse_x, g_mouse_y);
                else if (!(old_mouse_b & 1) && (mouse_b & 1))
                   mouse_func(GLUT_LEFT_BUTTON, GLUT_DOWN,   g_mouse_x, g_mouse_y);

                if ((old_mouse_b & 2) && !(mouse_b & 2))
                   mouse_func(GLUT_RIGHT_BUTTON, GLUT_UP,    g_mouse_x, g_mouse_y);
                else if (!(old_mouse_b & 2) && (mouse_b & 2))
                   mouse_func(GLUT_RIGHT_BUTTON, GLUT_DOWN,  g_mouse_x, g_mouse_y);

                if ((old_mouse_b & 4) && !(mouse_b & 4))
                   mouse_func(GLUT_MIDDLE_BUTTON, GLUT_UP,   g_mouse_x, g_mouse_y);
                else if (!(old_mouse_b & 3) && (mouse_b & 4))
                   mouse_func(GLUT_MIDDLE_BUTTON, GLUT_DOWN, g_mouse_x, g_mouse_y);
             }

             idle        = GL_FALSE;
             old_mouse_b = mouse_b;
          }
       }

       if (pc_keypressed()) {
          int key;
          int glut_key;

          idle = GL_FALSE;
          key  = pc_readkey();

          switch (key>>16) {
                 case KEY_F1:     glut_key = GLUT_KEY_F1;        goto special;
                 case KEY_F2:     glut_key = GLUT_KEY_F2;        goto special;
                 case KEY_F3:     glut_key = GLUT_KEY_F3;        goto special;
                 case KEY_F4:     glut_key = GLUT_KEY_F4;        goto special;
                 case KEY_F5:     glut_key = GLUT_KEY_F5;        goto special;
                 case KEY_F6:     glut_key = GLUT_KEY_F6;        goto special;
                 case KEY_F7:     glut_key = GLUT_KEY_F7;        goto special;
                 case KEY_F8:     glut_key = GLUT_KEY_F8;        goto special;
                 case KEY_F9:     glut_key = GLUT_KEY_F9;        goto special;
                 case KEY_F10:    glut_key = GLUT_KEY_F10;       goto special;
                 case KEY_F11:    glut_key = GLUT_KEY_F11;       goto special;
                 case KEY_F12:    glut_key = GLUT_KEY_F12;       goto special;
                 case KEY_LEFT:   glut_key = GLUT_KEY_LEFT;      goto special;
                 case KEY_UP:     glut_key = GLUT_KEY_UP;        goto special;
                 case KEY_RIGHT:  glut_key = GLUT_KEY_RIGHT;     goto special;
                 case KEY_DOWN:   glut_key = GLUT_KEY_DOWN;      goto special;
                 case KEY_PGUP:   glut_key = GLUT_KEY_PAGE_UP;   goto special;
                 case KEY_PGDN:   glut_key = GLUT_KEY_PAGE_DOWN; goto special;
                 case KEY_HOME:   glut_key = GLUT_KEY_HOME;      goto special;
                 case KEY_END:    glut_key = GLUT_KEY_END;       goto special;
                 case KEY_INSERT: glut_key = GLUT_KEY_INSERT;    goto special;
                 special:
                      if (g_curwin->special) {
                         g_curwin->special(glut_key, g_mouse_x, g_mouse_y);
                      }
                      break;
                 default:
                      if (g_curwin->keyboard) {
                         g_curwin->keyboard(key & 0xFF, g_mouse_x, g_mouse_y);
                      }
          }
       }

       if (idle && g_idle_func)
          g_idle_func();
 }
}