Subversion Repositories shark

Rev

Rev 55 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
55 pj 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.2 for Mesa 4.1
23
 *
24
 *  Copyright (C) 2002 - Borca Daniel
25
 *  Email : dborca@yahoo.com
26
 *  Web   : http://www.geocities.com/dborca
27
 */
28
 
29
 
30
#include "GL/glut.h"
31
#ifndef FX
32
#include "GL/dmesa.h"
33
#else
34
#include "GL/fxmesa.h"
35
#endif
36
#include "internal.h"
37
 
38
 
39
 
40
static int window;
41
 
42
#ifndef FX
43
static DMesaVisual  visual  = NULL;
44
static DMesaContext context = NULL;
45
static DMesaBuffer  buffer[MAX_WINDOWS];
46
#else
47
static void *visual = NULL;
48
static fxMesaContext context = NULL;
49
static int fx_attrib[32];
50
#endif
51
 
52
 
53
 
54
static void clean (void)
55
{
56
 int i;
57
 
58
 for (i=0; i<MAX_WINDOWS; i++) {
59
     glutDestroyWindow(i+1);
60
 }
61
#ifndef FX
62
 if (context) DMesaDestroyContext(context);
63
 if (visual)  DMesaDestroyVisual(visual);
64
#else
65
 if (context) fxMesaDestroyContext(context);
66
#endif
67
 
68
 pc_close_stdout();
69
 pc_close_stderr();
70
}
71
 
72
 
73
 
74
int APIENTRY glutCreateWindow (const char *title)
75
{
76
 int i;
77
 
78
 if (!visual) {
79
    int screen_w = DEFAULT_WIDTH;
80
    int screen_h = DEFAULT_HEIGHT;
81
 
82
    if ((g_width<=640) && (g_height<=480)) {
83
       screen_w = 640;
84
       screen_h = 480;
85
    } else if ((g_width<=800) && (g_height<=600)) {
86
       screen_w = 800;
87
       screen_h = 600;
88
    } else if ((g_width<=1024) && (g_height<=768)) {
89
       screen_w = 1024;
90
       screen_h = 768;
91
    }
92
 
93
#ifndef FX
94
    if ((visual=DMesaCreateVisual(screen_w, screen_h, DEFAULT_BPP,
95
                                  g_display_mode & GLUT_DOUBLE,
96
                                  g_display_mode & GLUT_DEPTH  ?DEPTH_SIZE  :0,
97
                                  g_display_mode & GLUT_STENCIL?STENCIL_SIZE:0,
98
                                  g_display_mode & GLUT_ACCUM  ?ACCUM_SIZE  :0))==NULL) {
99
       return 0;
100
    }
101
 
102
    if ((context=DMesaCreateContext(visual, NULL))==NULL) {
103
       DMesaDestroyVisual(visual);
104
       return 0;
105
    }
106
#else
107
    i = 0;
108
    if (g_display_mode & GLUT_DOUBLE) fx_attrib[i++] = FXMESA_DOUBLEBUFFER;
109
    if (g_display_mode & GLUT_DEPTH) { fx_attrib[i++] = FXMESA_DEPTH_SIZE; fx_attrib[i++] = DEPTH_SIZE; }
110
    if (g_display_mode & GLUT_STENCIL) { fx_attrib[i++] = FXMESA_STENCIL_SIZE; fx_attrib[i++] = STENCIL_SIZE; }
111
    if (g_display_mode & GLUT_ACCUM) { fx_attrib[i++] = FXMESA_ACCUM_SIZE; fx_attrib[i++] = ACCUM_SIZE; }
112
    fx_attrib[i] = FXMESA_NONE;
113
    if ((context=fxMesaCreateBestContext(-1, screen_w, screen_h, fx_attrib))==NULL) {
114
       return 0;
115
    }
116
    visual = context;
117
#endif
118
 
119
    pc_open_stdout();
120
    pc_open_stderr();
121
    pc_atexit(clean);
122
 }
123
 
124
#ifndef FX
125
 for (i=0; i<MAX_WINDOWS; i++) {
126
     if (!buffer[i]) {
127
        DMesaBuffer b;
128
 
129
        if ((b=DMesaCreateBuffer(visual, g_xpos, g_ypos, g_width, g_height))==NULL) {
130
           return 0;
131
        }
132
        if (!DMesaMakeCurrent(context, b)) {
133
           DMesaDestroyBuffer(b);
134
           return 0;
135
        }
136
        if (g_mouse) {
137
           pc_mouse_area(g_xpos, g_ypos, g_xpos + g_width - 1, g_ypos + g_height - 1);
138
        }
139
 
140
        buffer[window = i] = b;
141
        return i+1;
142
     }
143
 }
144
 
145
 return 0;
146
#else
147
 fxMesaMakeCurrent(context);
148
 
149
 return 1;
150
#endif
151
}
152
 
153
 
154
int APIENTRY glutCreateSubWindow (int win, int x, int y, int width, int height)
155
{
156
 return GL_FALSE;
157
}
158
 
159
 
160
void APIENTRY glutDestroyWindow (int win)
161
{
162
#ifndef FX
163
 if (buffer[win-1]) {
164
    DMesaDestroyBuffer(buffer[win-1]);
165
    buffer[win-1] = NULL;
166
 }
167
#endif
168
}
169
 
170
 
171
void APIENTRY glutPostRedisplay (void)
172
{
173
 g_redisplay = GL_TRUE;
174
}
175
 
176
 
177
void APIENTRY glutSwapBuffers (void)
178
{
179
 if (g_mouse) pc_scare_mouse();
180
#ifndef FX
181
 DMesaSwapBuffers(buffer[window]);
182
#else
183
 fxMesaSwapBuffers();
184
#endif
185
 if (g_mouse) pc_unscare_mouse();
186
}
187
 
188
 
189
int APIENTRY glutGetWindow (void)
190
{
191
 return window + 1;
192
}
193
 
194
 
195
void APIENTRY glutSetWindow (int win)
196
{
197
 window = win - 1;
198
}
199
 
200
 
201
void APIENTRY glutSetWindowTitle (const char *title)
202
{
203
}
204
 
205
 
206
void APIENTRY glutSetIconTitle (const char *title)
207
{
208
}
209
 
210
 
211
void APIENTRY glutPositionWindow (int x, int y)
212
{
213
#ifndef FX
214
 if (DMesaViewport(buffer[window], x, y, g_width, g_height)) {
215
    g_xpos = x;
216
    g_ypos = y;
217
 }
218
#endif
219
}
220
 
221
 
222
void APIENTRY glutReshapeWindow (int width, int height)
223
{
224
#ifndef FX
225
 if (DMesaViewport(buffer[window], g_xpos, g_ypos, width, height)) {
226
    g_width = width;
227
    g_height = height;
228
    if (reshape_func) {
229
       reshape_func(width, height);
230
    } else {
231
       glViewport(0, 0, width, height);
232
    }
233
 }
234
#endif
235
}
236
 
237
 
238
void APIENTRY glutPopWindow (void)
239
{
240
}
241
 
242
 
243
void APIENTRY glutPushWindow (void)
244
{
245
}
246
 
247
 
248
void APIENTRY glutIconifyWindow (void)
249
{
250
}
251
 
252
 
253
void APIENTRY glutShowWindow (void)
254
{
255
}
256
 
257
 
258
void APIENTRY glutHideWindow (void)
259
{
260
}