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 static GLuint swaptime
, swapcount
;
33 static DMesaVisual visual
= NULL
;
35 GLUTwindow
*_glut_current
, *_glut_windows
[MAX_WINDOWS
];
43 for (i
=1; i
<=MAX_WINDOWS
; i
++) {
46 if (visual
) DMesaDestroyVisual(visual
);
54 _glut_window (int win
)
56 if (win
> 0 && --win
< MAX_WINDOWS
) {
57 return _glut_windows
[win
];
64 glutCreateWindow (const char *title
)
67 int m8width
= (_glut_default
.width
+ 7) & ~7;
69 /* We set the Visual once. This will be our desktop (graphic mode).
70 * We should do this in the `glutInit' code, but we don't have any idea
71 * about its geometry. Supposedly, when we are about to create one
72 * window, we have a slight idea about resolution.
75 if ((visual
=DMesaCreateVisual(_glut_default
.x
+ m8width
, _glut_default
.y
+ _glut_default
.height
, _glut_visual
.bpp
, _glut_visual
.refresh
,
76 _glut_default
.mode
& GLUT_DOUBLE
,
77 !(_glut_default
.mode
& GLUT_INDEX
),
78 (_glut_default
.mode
& GLUT_ALPHA
) ? _glut_visual
.alpha
: 0,
79 (_glut_default
.mode
& GLUT_DEPTH
) ? _glut_visual
.depth
: 0,
80 (_glut_default
.mode
& GLUT_STENCIL
) ? _glut_visual
.stencil
: 0,
81 (_glut_default
.mode
& GLUT_ACCUM
) ? _glut_visual
.accum
: 0))==NULL
) {
85 DMesaGetIntegerv(DMESA_GET_SCREEN_SIZE
, _glut_visual
.geometry
);
86 DMesaGetIntegerv(DMESA_GET_DRIVER_CAPS
, &_glut_visual
.flags
);
88 /* Also hook stdio/stderr once */
94 /* Search for an empty slot.
95 * Each window has its own rendering Context and its own Buffer.
97 for (i
=0; i
<MAX_WINDOWS
; i
++) {
98 if (_glut_windows
[i
] == NULL
) {
103 if ((w
= (GLUTwindow
*)calloc(1, sizeof(GLUTwindow
))) == NULL
) {
107 /* Allocate the rendering Context. */
108 if ((c
= DMesaCreateContext(visual
, NULL
)) == NULL
) {
113 /* Allocate the Buffer (displayable area).
114 * We have to specify buffer size and position (inside the desktop).
116 if ((b
= DMesaCreateBuffer(visual
, _glut_default
.x
, _glut_default
.y
, m8width
, _glut_default
.height
)) == NULL
) {
117 DMesaDestroyContext(c
);
122 /* Bind Buffer to Context and make the Context the current one. */
123 if (!DMesaMakeCurrent(c
, b
)) {
124 DMesaDestroyBuffer(b
);
125 DMesaDestroyContext(c
);
130 _glut_current
= _glut_windows
[i
] = w
;
133 w
->xpos
= _glut_default
.x
;
134 w
->ypos
= _glut_default
.y
;
136 w
->height
= _glut_default
.height
;
149 glutCreateSubWindow (int win
, int x
, int y
, int width
, int height
)
156 glutDestroyWindow (int win
)
158 GLUTwindow
*w
= _glut_window(win
);
163 DMesaMakeCurrent(NULL
, NULL
);
164 DMesaDestroyBuffer(w
->buffer
);
165 DMesaDestroyContext(w
->context
);
167 _glut_windows
[win
- 1] = NULL
;
173 glutPostRedisplay (void)
175 _glut_current
->redisplay
= GL_TRUE
;
180 glutSwapBuffers (void)
182 if (_glut_current
->show_mouse
) {
183 /* XXX scare mouse */
184 DMesaSwapBuffers(_glut_current
->buffer
);
185 /* XXX unscare mouse */
187 DMesaSwapBuffers(_glut_current
->buffer
);
191 GLint t
= glutGet(GLUT_ELAPSED_TIME
);
195 else if (t
- swaptime
> _glut_fps
) {
196 double time
= 0.001 * (t
- swaptime
);
197 double fps
= (double)swapcount
/ time
;
198 fprintf(stderr
, "GLUT: %d frames in %.2f seconds = %.2f FPS\n", swapcount
, time
, fps
);
209 return _glut_current
->num
;
214 glutSetWindow (int win
)
216 GLUTwindow
*w
= _glut_window(win
);
219 DMesaMakeCurrent(_glut_current
->context
, _glut_current
->buffer
);
225 glutSetWindowTitle (const char *title
)
231 glutSetIconTitle (const char *title
)
237 glutPositionWindow (int x
, int y
)
239 if (DMesaMoveBuffer(x
, y
)) {
240 _glut_current
->xpos
= x
;
241 _glut_current
->ypos
= y
;
247 glutReshapeWindow (int width
, int height
)
249 if (DMesaResizeBuffer(width
, height
)) {
250 _glut_current
->width
= width
;
251 _glut_current
->height
= height
;
252 if (_glut_current
->reshape
) {
253 _glut_current
->reshape(width
, height
);
255 glViewport(0, 0, width
, height
);
262 glutFullScreen (void)
274 glutPushWindow (void)
280 glutIconifyWindow (void)
286 glutShowWindow (void)
292 glutHideWindow (void)
298 glutCloseFunc (GLUTdestroyCB destroy
)
300 _glut_current
->destroy
= destroy
;
305 glutPostWindowRedisplay (int win
)
307 GLUTwindow
*w
= _glut_window(win
);
309 w
->redisplay
= GL_TRUE
;
315 glutGetWindowData (void)
317 return _glut_current
->data
;
322 glutSetWindowData (void *data
)
324 _glut_current
->data
= data
;