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 if (!(_glut_default
.mode
& GLUT_DOUBLE
)) {
73 /* We set the Visual once. This will be our desktop (graphic mode).
74 * We should do this in the `glutInit' code, but we don't have any idea
75 * about its geometry. Supposedly, when we are about to create one
76 * window, we have a slight idea about resolution.
79 if ((visual
=DMesaCreateVisual(_glut_default
.x
+ m8width
, _glut_default
.y
+ _glut_default
.height
, _glut_visual
.bpp
, _glut_visual
.refresh
,
81 !(_glut_default
.mode
& GLUT_INDEX
),
82 (_glut_default
.mode
& GLUT_ALPHA
) ? _glut_visual
.alpha
: 0,
83 (_glut_default
.mode
& GLUT_DEPTH
) ? _glut_visual
.depth
: 0,
84 (_glut_default
.mode
& GLUT_STENCIL
) ? _glut_visual
.stencil
: 0,
85 (_glut_default
.mode
& GLUT_ACCUM
) ? _glut_visual
.accum
: 0))==NULL
) {
89 DMesaGetIntegerv(DMESA_GET_SCREEN_SIZE
, _glut_visual
.geometry
);
90 DMesaGetIntegerv(DMESA_GET_DRIVER_CAPS
, &_glut_visual
.flags
);
92 /* Also hook stdio/stderr once */
98 /* Search for an empty slot.
99 * Each window has its own rendering Context and its own Buffer.
101 for (i
=0; i
<MAX_WINDOWS
; i
++) {
102 if (_glut_windows
[i
] == NULL
) {
107 if ((w
= (GLUTwindow
*)calloc(1, sizeof(GLUTwindow
))) == NULL
) {
111 /* Allocate the rendering Context. */
112 if ((c
= DMesaCreateContext(visual
, NULL
)) == NULL
) {
117 /* Allocate the Buffer (displayable area).
118 * We have to specify buffer size and position (inside the desktop).
120 if ((b
= DMesaCreateBuffer(visual
, _glut_default
.x
, _glut_default
.y
, m8width
, _glut_default
.height
)) == NULL
) {
121 DMesaDestroyContext(c
);
126 /* Bind Buffer to Context and make the Context the current one. */
127 if (!DMesaMakeCurrent(c
, b
)) {
128 DMesaDestroyBuffer(b
);
129 DMesaDestroyContext(c
);
134 _glut_current
= _glut_windows
[i
] = w
;
137 w
->xpos
= _glut_default
.x
;
138 w
->ypos
= _glut_default
.y
;
140 w
->height
= _glut_default
.height
;
153 glutCreateSubWindow (int win
, int x
, int y
, int width
, int height
)
160 glutDestroyWindow (int win
)
162 GLUTwindow
*w
= _glut_window(win
);
167 DMesaMakeCurrent(NULL
, NULL
);
168 DMesaDestroyBuffer(w
->buffer
);
169 DMesaDestroyContext(w
->context
);
171 _glut_windows
[win
- 1] = NULL
;
177 glutPostRedisplay (void)
179 _glut_current
->redisplay
= GL_TRUE
;
184 glutSwapBuffers (void)
186 if (_glut_current
->show_mouse
) {
187 /* XXX scare mouse */
188 DMesaSwapBuffers(_glut_current
->buffer
);
189 /* XXX unscare mouse */
191 DMesaSwapBuffers(_glut_current
->buffer
);
195 GLint t
= glutGet(GLUT_ELAPSED_TIME
);
199 else if (t
- swaptime
> _glut_fps
) {
200 double time
= 0.001 * (t
- swaptime
);
201 double fps
= (double)swapcount
/ time
;
202 fprintf(stderr
, "GLUT: %d frames in %.2f seconds = %.2f FPS\n", swapcount
, time
, fps
);
213 return _glut_current
->num
;
218 glutSetWindow (int win
)
220 GLUTwindow
*w
= _glut_window(win
);
223 DMesaMakeCurrent(_glut_current
->context
, _glut_current
->buffer
);
229 glutSetWindowTitle (const char *title
)
235 glutSetIconTitle (const char *title
)
241 glutPositionWindow (int x
, int y
)
243 if (DMesaMoveBuffer(x
, y
)) {
244 _glut_current
->xpos
= x
;
245 _glut_current
->ypos
= y
;
251 glutReshapeWindow (int width
, int height
)
253 if (DMesaResizeBuffer(width
, height
)) {
254 _glut_current
->width
= width
;
255 _glut_current
->height
= height
;
256 if (_glut_current
->reshape
) {
257 _glut_current
->reshape(width
, height
);
259 glViewport(0, 0, width
, height
);
266 glutFullScreen (void)
278 glutPushWindow (void)
284 glutIconifyWindow (void)
290 glutShowWindow (void)
296 glutHideWindow (void)
302 glutCloseFunc (GLUTdestroyCB destroy
)
304 _glut_current
->destroy
= destroy
;
309 glutPostWindowRedisplay (int win
)
311 GLUTwindow
*w
= _glut_window(win
);
313 w
->redisplay
= GL_TRUE
;
319 glutGetWindowData (void)
321 return _glut_current
->data
;
326 glutSetWindowData (void *data
)
328 _glut_current
->data
= data
;