source: trunk/src/opengl/glut/win32_glx.c

Last change on this file was 2996, checked in by jeroen, 25 years ago

* empty log message *

File size: 7.0 KB
Line 
1/* $Id: win32_glx.c,v 1.3 2000-03-04 19:10:16 jeroen Exp $ */
2/* Copyright (c) Nate Robins, 1997. */
3
4/* This program is freely distributable without licensing fees
5 and is provided without guarantee or warrantee expressed or
6 implied. This program is -not- in the public domain. */
7
8#include <stdio.h>
9#if defined(__WIN32OS2__)
10#include "os2_glx.h"
11//#include "wgl.h"
12#include "pfddefs.h"
13#include <memory.h>
14#else
15#include "win32_glx.h"
16#endif
17
18/* global current HDC */
19extern HDC XHDC;
20
21GLXContext
22glXCreateContext(Display * display, XVisualInfo * visinfo,
23 GLXContext share, Bool direct)
24{
25 /* KLUDGE: GLX really expects a display pointer to be passed
26 in as the first parameter, but Win32 needs an HDC instead,
27 so BE SURE that the global XHDC is set before calling this
28 routine. */
29 HGLRC context;
30
31 context = wglCreateContext(XHDC);
32
33#if 0
34 /* XXX GLUT doesn't support it now, so don't worry about display list
35 and texture object sharing. */
36 if (share) {
37 wglShareLists(share, context);
38 }
39#endif
40
41 /* Since direct rendering is implicit, the direct flag is
42 ignored. */
43
44 return context;
45}
46
47int
48glXGetConfig(Display * display, XVisualInfo * visual, int attrib, int *value)
49{
50 if (!visual)
51 return GLX_BAD_VISUAL;
52
53 switch (attrib) {
54 case GLX_USE_GL:
55 if (visual->dwFlags & (PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW)) {
56 /* XXX Brad's Matrix Millenium II has problems creating
57 color index windows in 24-bit mode (lead to GDI crash)
58 and 32-bit mode (lead to black window). The cColorBits
59 filed of the PIXELFORMATDESCRIPTOR returned claims to
60 have 24 and 32 bits respectively of color indices. 2^24
61 and 2^32 are ridiculously huge writable colormaps.
62 Assume that if we get back a color index
63 PIXELFORMATDESCRIPTOR with 24 or more bits, the
64 PIXELFORMATDESCRIPTOR doesn't really work and skip it.
65 -mjk */
66 if (visual->iPixelType == PFD_TYPE_COLORINDEX
67 && visual->cColorBits >= 24) {
68 *value = 0;
69 } else {
70 *value = 1;
71 }
72 } else {
73 *value = 0;
74 }
75 break;
76 case GLX_BUFFER_SIZE:
77 /* KLUDGE: if we're RGBA, return the number of bits/pixel,
78 otherwise, return 8 (we guessed at 256 colors in CI
79 mode). */
80 if (visual->iPixelType == PFD_TYPE_RGBA)
81 *value = visual->cColorBits;
82 else
83 *value = 8;
84 break;
85 case GLX_LEVEL:
86 /* The bReserved flag of the pfd contains the
87 overlay/underlay info. */
88 *value = visual->bReserved;
89 break;
90 case GLX_RGBA:
91 *value = visual->iPixelType == PFD_TYPE_RGBA;
92 break;
93 case GLX_DOUBLEBUFFER:
94 *value = visual->dwFlags & PFD_DOUBLEBUFFER;
95 break;
96 case GLX_STEREO:
97 *value = visual->dwFlags & PFD_STEREO;
98 break;
99 case GLX_AUX_BUFFERS:
100 *value = visual->cAuxBuffers;
101 break;
102 case GLX_RED_SIZE:
103 *value = visual->cRedBits;
104 break;
105 case GLX_GREEN_SIZE:
106 *value = visual->cGreenBits;
107 break;
108 case GLX_BLUE_SIZE:
109 *value = visual->cBlueBits;
110 break;
111 case GLX_ALPHA_SIZE:
112 *value = visual->cAlphaBits;
113 break;
114 case GLX_DEPTH_SIZE:
115 *value = visual->cDepthBits;
116 break;
117 case GLX_STENCIL_SIZE:
118 *value = visual->cStencilBits;
119 break;
120 case GLX_ACCUM_RED_SIZE:
121 *value = visual->cAccumRedBits;
122 break;
123 case GLX_ACCUM_GREEN_SIZE:
124 *value = visual->cAccumGreenBits;
125 break;
126 case GLX_ACCUM_BLUE_SIZE:
127 *value = visual->cAccumBlueBits;
128 break;
129 case GLX_ACCUM_ALPHA_SIZE:
130 *value = visual->cAccumAlphaBits;
131 break;
132 default:
133 return GLX_BAD_ATTRIB;
134 }
135 return 0;
136}
137
138XVisualInfo *
139glXChooseVisual(Display * display, int screen, int *attribList)
140{
141 /* KLUDGE: since we need the HDC, MAKE SURE to set XHDC
142 before calling this routine. */
143
144 int *p = attribList;
145 int pf;
146 PIXELFORMATDESCRIPTOR pfd;
147 PIXELFORMATDESCRIPTOR *match = NULL;
148 int stereo = 0;
149
150 /* Avoid seg-faults. */
151 if (!p)
152 return NULL;
153
154 memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
155 pfd.nSize = (sizeof(PIXELFORMATDESCRIPTOR));
156 pfd.nVersion = 1;
157
158 /* Defaults. */
159 pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
160 pfd.iPixelType = PFD_TYPE_COLORINDEX;
161 pfd.cColorBits = 32;
162 pfd.cDepthBits = 0;
163
164 while (*p) {
165 switch (*p) {
166 case GLX_USE_GL:
167 pfd.dwFlags |= PFD_SUPPORT_OPENGL;
168 break;
169 case GLX_BUFFER_SIZE:
170 pfd.cColorBits = *(++p);
171 break;
172 case GLX_LEVEL:
173 /* the bReserved flag of the pfd contains the
174 overlay/underlay info. */
175 pfd.bReserved = *(++p);
176 break;
177 case GLX_RGBA:
178 pfd.iPixelType = PFD_TYPE_RGBA;
179 break;
180 case GLX_DOUBLEBUFFER:
181 pfd.dwFlags |= PFD_DOUBLEBUFFER;
182 break;
183 case GLX_STEREO:
184 stereo = 1;
185 pfd.dwFlags |= PFD_STEREO;
186 break;
187 case GLX_AUX_BUFFERS:
188 pfd.cAuxBuffers = *(++p);
189 break;
190 case GLX_RED_SIZE:
191 pfd.cRedBits = 8; /* Try to get the maximum.*/
192 ++p;
193 break;
194 case GLX_GREEN_SIZE:
195 pfd.cGreenBits = 8;
196 ++p;
197 break;
198 case GLX_BLUE_SIZE:
199 pfd.cBlueBits = 8;
200 ++p;
201 break;
202 case GLX_ALPHA_SIZE:
203 pfd.cAlphaBits = 8;
204 ++p;
205 break;
206 case GLX_DEPTH_SIZE:
207 pfd.cDepthBits = 32;
208 ++p;
209 break;
210 case GLX_STENCIL_SIZE:
211 pfd.cStencilBits = *(++p);
212 break;
213 case GLX_ACCUM_RED_SIZE:
214 case GLX_ACCUM_GREEN_SIZE:
215 case GLX_ACCUM_BLUE_SIZE:
216 case GLX_ACCUM_ALPHA_SIZE:
217 /* I believe that WGL only used the cAccumRedBits,
218 cAccumBlueBits, cAccumGreenBits, and cAccumAlphaBits fields
219 when returning info about the accumulation buffer precision.
220 Only cAccumBits is used for requesting an accumulation
221 buffer. */
222 pfd.cAccumBits = 1;
223 ++p;
224 break;
225 }
226 ++p;
227 }
228
229 /* Let Win32 choose one for us. */
230 pf = ChoosePixelFormat(XHDC, &pfd);
231 if (pf > 0) {
232 match = (PIXELFORMATDESCRIPTOR *) malloc(sizeof(PIXELFORMATDESCRIPTOR));
233 DescribePixelFormat(XHDC, pf, sizeof(PIXELFORMATDESCRIPTOR), match);
234
235 /* ChoosePixelFormat is dumb in that it will return a pixel
236 format that doesn't have stereo even if it was requested
237 so we need to make sure that if stereo was selected, we
238 got it. */
239 if (stereo) {
240 if (!(match->dwFlags & PFD_STEREO)) {
241 free(match);
242 return NULL;
243 }
244 }
245 /* XXX Brad's Matrix Millenium II has problems creating
246 color index windows in 24-bit mode (lead to GDI crash)
247 and 32-bit mode (lead to black window). The cColorBits
248 filed of the PIXELFORMATDESCRIPTOR returned claims to
249 have 24 and 32 bits respectively of color indices. 2^24
250 and 2^32 are ridiculously huge writable colormaps.
251 Assume that if we get back a color index
252 PIXELFORMATDESCRIPTOR with 24 or more bits, the
253 PIXELFORMATDESCRIPTOR doesn't really work and skip it.
254 -mjk */
255 if (match->iPixelType == PFD_TYPE_COLORINDEX
256 && match->cColorBits >= 24) {
257 free(match);
258 return NULL;
259 }
260 }
261 return match;
262}
Note: See TracBrowser for help on using the repository browser.