2 * Mesa 3-D graphics library
4 * Copyright (C) 1995-1998 Brian Paul
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.
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.
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.
22 * DOS/DJGPP glut driver v1.4 for Mesa
24 * Copyright (C) 2002 - Borca Daniel
25 * Email : dborca@users.sourceforge.net
26 * Web : http://www.geocities.com/dborca
38 static GLuint swaptime
, swapcount
;
40 static DMesaVisual visual
= NULL
;
41 GLUTwindow
*g_windows
[MAX_WINDOWS
];
45 static void clean (void)
49 for (i
=1; i
<=MAX_WINDOWS
; i
++) {
52 if (visual
) DMesaDestroyVisual(visual
);
60 int APIENTRY
glutCreateWindow (const char *title
)
63 int m8width
= (g_init_w
+ 7) & ~7;
65 /* We set the Visual once. This will be our desktop (graphic mode).
66 * We should do this in the `glutInit' code, but we don't have any idea
67 * about its geometry. Supposedly, when we are about to create one
68 * window, we have a slight idea about resolution.
71 if ((visual
=DMesaCreateVisual(g_init_x
+ m8width
, g_init_y
+ g_init_h
, g_bpp
, g_refresh
,
72 g_display_mode
& GLUT_DOUBLE
,
73 !(g_display_mode
& GLUT_INDEX
),
74 (g_display_mode
& GLUT_ALPHA
) ? g_alpha
: 0,
75 (g_display_mode
& GLUT_DEPTH
) ? g_depth
: 0,
76 (g_display_mode
& GLUT_STENCIL
) ? g_stencil
: 0,
77 (g_display_mode
& GLUT_ACCUM
) ? g_accum
: 0))==NULL
) {
81 /* Also hook stdio/stderr once */
87 /* Search for an empty slot.
88 * Each window has its own rendering Context and its own Buffer.
90 for (i
=0; i
<MAX_WINDOWS
; i
++) {
91 if (g_windows
[i
] == NULL
) {
96 if ((w
= (GLUTwindow
*)calloc(1, sizeof(GLUTwindow
))) == NULL
) {
100 /* Allocate the rendering Context. */
101 if ((c
= DMesaCreateContext(visual
, NULL
)) == NULL
) {
106 /* Allocate the Buffer (displayable area).
107 * We have to specify buffer size and position (inside the desktop).
109 if ((b
= DMesaCreateBuffer(visual
, g_init_x
, g_init_y
, m8width
, g_init_h
)) == NULL
) {
110 DMesaDestroyContext(c
);
115 /* Bind Buffer to Context and make the Context the current one. */
116 if (!DMesaMakeCurrent(c
, b
)) {
117 DMesaDestroyBuffer(b
);
118 DMesaDestroyContext(c
);
123 g_curwin
= g_windows
[i
] = w
;
129 w
->height
= g_init_h
;
142 int APIENTRY
glutCreateSubWindow (int win
, int x
, int y
, int width
, int height
)
149 void APIENTRY
glutDestroyWindow (int win
)
151 if (g_windows
[--win
]) {
152 GLUTwindow
*w
= g_windows
[win
];
153 DMesaMakeCurrent(NULL
, NULL
);
154 DMesaDestroyBuffer(w
->buffer
);
155 DMesaDestroyContext(w
->context
);
157 g_windows
[win
] = NULL
;
163 void APIENTRY
glutPostRedisplay (void)
165 g_curwin
->redisplay
= GL_TRUE
;
170 void APIENTRY
glutSwapBuffers (void)
172 if (g_curwin
->show_mouse
) {
173 /* XXX scare mouse */
174 DMesaSwapBuffers(g_curwin
->buffer
);
175 /* XXX unscare mouse */
177 DMesaSwapBuffers(g_curwin
->buffer
);
181 GLint t
= glutGet(GLUT_ELAPSED_TIME
);
185 else if (t
- swaptime
> g_fps
) {
186 double time
= 0.001 * (t
- swaptime
);
187 double fps
= (double)swapcount
/ time
;
188 fprintf(stderr
, "GLUT: %d frames in %.2f seconds = %.2f FPS\n", swapcount
, time
, fps
);
197 int APIENTRY
glutGetWindow (void)
199 return g_curwin
->num
;
204 void APIENTRY
glutSetWindow (int win
)
206 g_curwin
= g_windows
[win
- 1];
207 DMesaMakeCurrent(g_curwin
->context
, g_curwin
->buffer
);
212 void APIENTRY
glutSetWindowTitle (const char *title
)
218 void APIENTRY
glutSetIconTitle (const char *title
)
224 void APIENTRY
glutPositionWindow (int x
, int y
)
226 if (DMesaMoveBuffer(x
, y
)) {
234 void APIENTRY
glutReshapeWindow (int width
, int height
)
236 if (DMesaResizeBuffer(width
, height
)) {
237 g_curwin
->width
= width
;
238 g_curwin
->height
= height
;
239 if (g_curwin
->reshape
) {
240 g_curwin
->reshape(width
, height
);
242 glViewport(0, 0, width
, height
);
249 void APIENTRY
glutFullScreen (void)
255 void APIENTRY
glutPopWindow (void)
261 void APIENTRY
glutPushWindow (void)
267 void APIENTRY
glutIconifyWindow (void)
273 void APIENTRY
glutShowWindow (void)
279 void APIENTRY
glutHideWindow (void)