DOS updates for new tree (Daniel Borca)
[mesa.git] / src / glut / dos / window.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 4.1
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 <stdio.h>
31
32 #include "glutint.h"
33 #include "GL/dmesa.h"
34
35
36
37 GLUTwindow *g_curwin;
38 static GLuint swaptime, swapcount;
39
40 static DMesaVisual visual = NULL;
41 static DMesaContext context = NULL;
42 static GLUTwindow *windows[MAX_WINDOWS];
43
44
45
46 static void clean (void)
47 {
48 int i;
49
50 for (i=1; i<=MAX_WINDOWS; i++) {
51 glutDestroyWindow(i);
52 }
53 if (context) DMesaDestroyContext(context);
54 if (visual) DMesaDestroyVisual(visual);
55
56 pc_close_stdout();
57 pc_close_stderr();
58 }
59
60
61
62 int APIENTRY glutCreateWindow (const char *title)
63 {
64 int i;
65 int m8width = (g_init_w + 7) & ~7;
66
67 if (!visual) {
68 if ((visual=DMesaCreateVisual(g_init_x + m8width, g_init_y + g_init_h, g_bpp, g_refresh,
69 g_display_mode & GLUT_DOUBLE,
70 !(g_display_mode & GLUT_INDEX),
71 g_display_mode & GLUT_ALPHA,
72 g_display_mode & GLUT_DEPTH ?DEPTH_SIZE :0,
73 g_display_mode & GLUT_STENCIL?STENCIL_SIZE:0,
74 g_display_mode & GLUT_ACCUM ?ACCUM_SIZE :0))==NULL) {
75 return 0;
76 }
77
78 if ((context=DMesaCreateContext(visual, NULL))==NULL) {
79 DMesaDestroyVisual(visual);
80 return 0;
81 }
82
83 pc_open_stdout();
84 pc_open_stderr();
85 pc_atexit(clean);
86 }
87
88 for (i=0; i<MAX_WINDOWS; i++) {
89 if (windows[i] == NULL) {
90 DMesaBuffer b;
91 GLUTwindow *w;
92
93 if ((w=(GLUTwindow *)calloc(1, sizeof(GLUTwindow))) == NULL) {
94 return 0;
95 }
96
97 if ((b=DMesaCreateBuffer(visual, g_init_x, g_init_y, m8width, g_init_h))==NULL) {
98 free(w);
99 return 0;
100 }
101 if (!DMesaMakeCurrent(context, b)) {
102 DMesaDestroyBuffer(b);
103 free(w);
104 return 0;
105 }
106
107 g_curwin = windows[i] = w;
108
109 w->num = ++i;
110 w->xpos = g_init_x;
111 w->ypos = g_init_y;
112 w->width = m8width;
113 w->height = g_init_h;
114 w->buffer = b;
115
116 return i;
117 }
118 }
119
120 return 0;
121 }
122
123
124
125 int APIENTRY glutCreateSubWindow (int win, int x, int y, int width, int height)
126 {
127 return GL_FALSE;
128 }
129
130
131
132 void APIENTRY glutDestroyWindow (int win)
133 {
134 if (windows[--win]) {
135 DMesaDestroyBuffer(windows[win]->buffer);
136 free(windows[win]);
137 windows[win] = NULL;
138 }
139 }
140
141
142
143 void APIENTRY glutPostRedisplay (void)
144 {
145 g_redisplay = GL_TRUE;
146 }
147
148
149
150 void APIENTRY glutSwapBuffers (void)
151 {
152 if (g_curwin->show_mouse) {
153 /* XXX scare mouse */
154 DMesaSwapBuffers(g_curwin->buffer);
155 /* XXX unscare mouse */
156 } else {
157 DMesaSwapBuffers(g_curwin->buffer);
158 }
159
160 if (g_fps) {
161 GLint t = glutGet(GLUT_ELAPSED_TIME);
162 swapcount++;
163 if (swaptime == 0)
164 swaptime = t;
165 else if (t - swaptime > g_fps) {
166 double time = 0.001 * (t - swaptime);
167 double fps = (double)swapcount / time;
168 fprintf(stderr, "GLUT: %d frames in %.2f seconds = %.2f FPS\n", swapcount, time, fps);
169 swaptime = t;
170 swapcount = 0;
171 }
172 }
173 }
174
175
176
177 int APIENTRY glutGetWindow (void)
178 {
179 return g_curwin->num;
180 }
181
182
183
184 void APIENTRY glutSetWindow (int win)
185 {
186 g_curwin = windows[win - 1];
187 }
188
189
190
191 void APIENTRY glutSetWindowTitle (const char *title)
192 {
193 }
194
195
196
197 void APIENTRY glutSetIconTitle (const char *title)
198 {
199 }
200
201
202
203 void APIENTRY glutPositionWindow (int x, int y)
204 {
205 if (DMesaMoveBuffer(x, y)) {
206 g_curwin->xpos = x;
207 g_curwin->ypos = y;
208 }
209 }
210
211
212
213 void APIENTRY glutReshapeWindow (int width, int height)
214 {
215 if (DMesaResizeBuffer(width, height)) {
216 g_curwin->width = width;
217 g_curwin->height = height;
218 if (g_curwin->reshape) {
219 g_curwin->reshape(width, height);
220 } else {
221 glViewport(0, 0, width, height);
222 }
223 }
224 }
225
226
227
228 void APIENTRY glutFullScreen (void)
229 {
230 }
231
232
233
234 void APIENTRY glutPopWindow (void)
235 {
236 }
237
238
239
240 void APIENTRY glutPushWindow (void)
241 {
242 }
243
244
245
246 void APIENTRY glutIconifyWindow (void)
247 {
248 }
249
250
251
252 void APIENTRY glutShowWindow (void)
253 {
254 }
255
256
257
258 void APIENTRY glutHideWindow (void)
259 {
260 }