DOS driver update
[mesa.git] / src / glut / dos / window.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 4.0
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.0 for Mesa 4.0
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 #include "GL/dmesa.h"
32 #include "internal.h"
33
34
35
36 static int window;
37
38 static DMesaVisual visual = NULL;
39 static DMesaContext context = NULL;
40 static DMesaBuffer buffer[MAX_WINDOWS];
41
42
43
44 static void clean (void)
45 {
46 int i;
47
48 for (i=0; i<MAX_WINDOWS; i++) {
49 glutDestroyWindow(i+1);
50 }
51 if (context) DMesaDestroyContext(context);
52 if (visual) DMesaDestroyVisual(visual);
53
54 pc_close_stdout();
55 pc_close_stderr();
56 }
57
58
59
60 int APIENTRY glutCreateWindow (const char *title)
61 {
62 int i;
63
64 if (!visual) {
65 int screen_w = DEFAULT_WIDTH;
66 int screen_h = DEFAULT_HEIGHT;
67
68 if ((g_width<=640) && (g_height<=480)) {
69 screen_w = 640;
70 screen_h = 480;
71 } else if ((g_width<=800) && (g_height<=600)) {
72 screen_w = 800;
73 screen_h = 600;
74 } else if ((g_width<=1024) && (g_height<=768)) {
75 screen_w = 1024;
76 screen_h = 768;
77 }
78
79 if ((visual=DMesaCreateVisual(screen_w, screen_h, DEFAULT_BPP,
80 g_display_mode & GLUT_DOUBLE,
81 g_display_mode & GLUT_DEPTH ?DEPTH_SIZE :0,
82 g_display_mode & GLUT_STENCIL?STENCIL_SIZE:0,
83 g_display_mode & GLUT_ACCUM ?ACCUM_SIZE :0))==NULL) {
84 return 0;
85 }
86
87 if ((context=DMesaCreateContext(visual, NULL))==NULL) {
88 DMesaDestroyVisual(visual);
89 return 0;
90 }
91
92 pc_open_stdout();
93 pc_open_stderr();
94 pc_atexit(clean);
95 }
96
97 for (i=0; i<MAX_WINDOWS; i++) {
98 if (!buffer[i]) {
99 DMesaBuffer b;
100
101 if ((b=DMesaCreateBuffer(visual, g_xpos, g_ypos, g_width, g_height))==NULL) {
102 return 0;
103 }
104 if (!DMesaMakeCurrent(context, b)) {
105 DMesaDestroyBuffer(b);
106 return 0;
107 }
108 if (g_mouse) {
109 pc_mouse_area(g_xpos, g_ypos, g_xpos + g_width - 1, g_ypos + g_height - 1);
110 }
111
112 buffer[window = i] = b;
113 return i+1;
114 }
115 }
116
117 return 0;
118 }
119
120
121 int APIENTRY glutCreateSubWindow (int win, int x, int y, int width, int height)
122 {
123 return GL_FALSE;
124 }
125
126
127 void APIENTRY glutDestroyWindow (int win)
128 {
129 if (buffer[win-1]) {
130 DMesaDestroyBuffer(buffer[win-1]);
131 buffer[win-1] = NULL;
132 }
133 }
134
135
136 void APIENTRY glutPostRedisplay (void)
137 {
138 g_redisplay = GL_TRUE;
139 }
140
141
142 void APIENTRY glutSwapBuffers (void)
143 {
144 if (g_mouse) pc_scare_mouse();
145 DMesaSwapBuffers(buffer[window]);
146 if (g_mouse) pc_unscare_mouse();
147 }
148
149
150 int APIENTRY glutGetWindow (void)
151 {
152 return window + 1;
153 }
154
155
156 void APIENTRY glutSetWindow (int win)
157 {
158 window = win - 1;
159 }
160
161
162 void APIENTRY glutSetWindowTitle (const char *title)
163 {
164 }
165
166
167 void APIENTRY glutSetIconTitle (const char *title)
168 {
169 }
170
171
172 void APIENTRY glutPositionWindow (int x, int y)
173 {
174 if (DMesaViewport(buffer[window], x, y, g_width, g_height)) {
175 g_xpos = x;
176 g_ypos = y;
177 }
178 }
179
180
181 void APIENTRY glutReshapeWindow (int width, int height)
182 {
183 if (DMesaViewport(buffer[window], g_xpos, g_ypos, width, height)) {
184 g_width = width;
185 g_height = height;
186 if (reshape_func) {
187 reshape_func(width, height);
188 } else {
189 glViewport(0, 0, width, height);
190 }
191 }
192 }
193
194
195 void APIENTRY glutPopWindow (void)
196 {
197 }
198
199
200 void APIENTRY glutPushWindow (void)
201 {
202 }
203
204
205 void APIENTRY glutIconifyWindow (void)
206 {
207 }
208
209
210 void APIENTRY glutShowWindow (void)
211 {
212 }
213
214
215 void APIENTRY glutHideWindow (void)
216 {
217 }