root/trunk/gl/wgl.d

Revision 157, 7.4 kB (checked in by jpelcis, 6 years ago)

Added an OpenAL implementation with ALUT.

Added an OpenGL implementation with all extensions, GLU, and GLUT.

Removed a second copy of d3d9.d.

Line 
1 module c.gl.wgl;
2
3 version (Windows) {
4 private import c.gl.gl;
5 private import std.c.windows.windows, std.loader;
6 import c.gl.wglext;
7
8 /*
9  * Constants
10  */
11 const ubyte WGL_FONT_LINES  = 0;
12 const ubyte WGL_FONT_POLYGONS   = 1;
13
14 const ubyte LPD_TYPE_RGBA   = 0;
15 const ubyte LPD_TYPE_COLORINDEX = 1;
16
17 // wglSwapLayerBuffers flags
18 const uint WGL_SWAP_MAIN_PLANE  = 0x00000001;
19 const uint WGL_SWAP_OVERLAY1    = 0x00000002;
20 const uint WGL_SWAP_OVERLAY2    = 0x00000004;
21 const uint WGL_SWAP_OVERLAY3    = 0x00000008;
22 const uint WGL_SWAP_OVERLAY4    = 0x00000010;
23 const uint WGL_SWAP_OVERLAY5    = 0x00000020;
24 const uint WGL_SWAP_OVERLAY6    = 0x00000040;
25 const uint WGL_SWAP_OVERLAY7    = 0x00000080;
26 const uint WGL_SWAP_OVERLAY8    = 0x00000100;
27 const uint WGL_SWAP_OVERLAY9    = 0x00000200;
28 const uint WGL_SWAP_OVERLAY10   = 0x00000400;
29 const uint WGL_SWAP_OVERLAY11   = 0x00000800;
30 const uint WGL_SWAP_OVERLAY12   = 0x00001000;
31 const uint WGL_SWAP_OVERLAY13   = 0x00002000;
32 const uint WGL_SWAP_OVERLAY14   = 0x00004000;
33 const uint WGL_SWAP_OVERLAY15   = 0x00008000;
34 const uint WGL_SWAP_UNDERLAY1   = 0x00010000;
35 const uint WGL_SWAP_UNDERLAY2   = 0x00020000;
36 const uint WGL_SWAP_UNDERLAY3   = 0x00040000;
37 const uint WGL_SWAP_UNDERLAY4   = 0x00080000;
38 const uint WGL_SWAP_UNDERLAY5   = 0x00100000;
39 const uint WGL_SWAP_UNDERLAY6   = 0x00200000;
40 const uint WGL_SWAP_UNDERLAY7   = 0x00400000;
41 const uint WGL_SWAP_UNDERLAY8   = 0x00800000;
42 const uint WGL_SWAP_UNDERLAY9   = 0x01000000;
43 const uint WGL_SWAP_UNDERLAY10  = 0x02000000;
44 const uint WGL_SWAP_UNDERLAY11  = 0x04000000;
45 const uint WGL_SWAP_UNDERLAY12  = 0x08000000;
46 const uint WGL_SWAP_UNDERLAY13  = 0x10000000;
47 const uint WGL_SWAP_UNDERLAY14  = 0x20000000;
48 const uint WGL_SWAP_UNDERLAY15  = 0x40000000;
49
50 // LAYERPLANEDESCRIPTOR flags
51 const uint LPD_DOUBLEBUFFER = 0x00000001;
52 const uint LPD_STEREO       = 0x00000002;
53 const uint LPD_SUPPORT_GDI  = 0x00000010;
54 const uint LPD_SUPPORT_OPENGL   = 0x00000020;
55 const uint LPD_SHARE_DEPTH  = 0x00000040;
56 const uint LPD_SHARE_STENCIL    = 0x00000080;
57 const uint LPD_SHARE_ACCUM  = 0x00000100;
58 const uint LPD_SWAP_EXCHANGE    = 0x00000200;
59 const uint LPD_SWAP_COPY    = 0x00000400;
60 const uint LPD_TRANSPARENT  = 0x00001000;
61
62 /*
63  * Structs and classes
64  */
65 struct _POINTFLOAT {
66     FLOAT       x;
67     FLOAT       y;
68 }
69 alias _POINTFLOAT POINTFLOAT;
70 alias _POINTFLOAT* PPOINTFLOAT;
71
72 struct _GLYPHMETRICSFLOAT {
73     FLOAT       gmfBlackBoxX;
74     FLOAT       gmfBlackBoxY;
75     POINTFLOAT  gmfptGlyphOrigin;
76     FLOAT       gmfCellIncX;
77     FLOAT       gmfCellIncY;
78 }
79 alias _GLYPHMETRICSFLOAT GLYPHMETRICSFLOAT;
80 alias _GLYPHMETRICSFLOAT* PGLYPHMETRICSFLOAT, LPGLYPHMETRICSFLOAT;
81
82 struct tagLAYERPLANEDESCRIPTOR {
83     WORD        nSize;
84     WORD        nVersion;
85     DWORD       dwFlags;
86     BYTE        iPixelType;
87     BYTE        cColorBits;
88     BYTE        cRedBits;
89     BYTE        cRedShift;
90     BYTE        cGreenBits;
91     BYTE        cGreenShift;
92     BYTE        cBlueBits;
93     BYTE        cBlueShift;
94     BYTE        cAlphaBits;
95     BYTE        cAlphaShift;
96     BYTE        cAccumBits;
97     BYTE        cAccumRedBits;
98     BYTE        cAccumGreenBits;
99     BYTE        cAccumBlueBits;
100     BYTE        cAccumAlphaBits;
101     BYTE        cDepthBits;
102     BYTE        cStencilBits;
103     BYTE        cAuxBuffers;
104     BYTE        iLayerPlane;
105     BYTE        bReserved;
106     COLORREF    crTransparent;
107 }
108 alias tagLAYERPLANEDESCRIPTOR LAYERPLANEDESCRIPTOR;
109 alias tagLAYERPLANEDESCRIPTOR* PLAYERPLANEDESCRIPTOR, LPLAYERPLANEDESCRIPTOR;
110
111 /*
112  * Functions
113  */
114 private HXModule wgldrv;
115 private void* getProc(char[] procname) {
116     void* symbol = ExeModule_GetSymbol(wgldrv, procname);
117     if (symbol is null) {
118         printf ("Failed to load WGL proc address " ~ procname ~ ".\n");
119     }
120     return (symbol);
121 }
122
123 static this () {
124     wgldrv = ExeModule_Load("OpenGL32.dll");
125 //  SwapBuffers = cast(pfSwapBuffers)getProc("SwapBuffers");
126     wglCopyContext = cast(pfwglCopyContext)getProc("wglCopyContext");
127     wglCreateContext = cast(pfwglCreateContext)getProc("wglCreateContext");
128     wglCreateLayerContext = cast(pfwglCreateLayerContext)getProc("wglCreateLayerContext");
129     wglDeleteContext = cast(pfwglDeleteContext)getProc("wglDeleteContext");
130     wglDescribeLayerPlane = cast(pfwglDescribeLayerPlane)getProc("wglDescribeLayerPlane");
131     wglGetCurrentContext = cast(pfwglGetCurrentContext)getProc("wglGetCurrentContext");
132     wglGetCurrentDC = cast(pfwglGetCurrentDC)getProc("wglGetCurrentDC");
133     wglGetLayerPaletteEntries = cast(pfwglGetLayerPaletteEntries)getProc("wglGetLayerPaletteEntries");
134     wglGetProcAddress = cast(pfwglGetProcAddress)getProc("wglGetProcAddress");
135     wglMakeCurrent = cast(pfwglMakeCurrent)getProc("wglMakeCurrent");
136     wglRealizeLayerPalette = cast(pfwglRealizeLayerPalette)getProc("wglRealizeLayerPalette");
137     wglSetLayerPaletteEntries = cast(pfwglSetLayerPaletteEntries)getProc("wglSetLayerPaletteEntries");
138     wglShareLists = cast(pfwglShareLists)getProc("wglShareLists");
139     wglSwapLayerBuffers = cast(pfwglSwapLayerBuffers)getProc("wglSwapLayerBuffers");
140     wglUseFontBitmapsA = cast(pfwglUseFontBitmapsA)getProc("wglUseFontBitmapsA");
141     wglUseFontBitmapsW = cast(pfwglUseFontBitmapsW)getProc("wglUseFontBitmapsW");
142     wglUseFontOutlinesA = cast(pfwglUseFontOutlinesA)getProc("wglUseFontOutlinesA");
143     wglUseFontOutlinesW = cast(pfwglUseFontOutlinesW)getProc("wglUseFontOutlinesW");
144 }
145
146 static ~this () {
147     ExeModule_Release(wgldrv);
148 }
149
150 /*
151  * Functions
152  */
153 extern (Windows):
154 typedef BOOL function(HDC) pfSwapBuffers;
155 typedef BOOL function(HGLRC, HGLRC, UINT) pfwglCopyContext;
156 typedef HGLRC function(HDC) pfwglCreateContext;
157 typedef HGLRC function(HDC, GLint) pfwglCreateLayerContext;
158 typedef BOOL function(HGLRC) pfwglDeleteContext;
159 typedef BOOL function(HDC, GLint, GLint, UINT, LPLAYERPLANEDESCRIPTOR) pfwglDescribeLayerPlane;
160 typedef HGLRC function() pfwglGetCurrentContext;
161 typedef HDC function() pfwglGetCurrentDC;
162 typedef int function(HDC, GLint, GLint, GLint, COLORREF*) pfwglGetLayerPaletteEntries;
163 typedef FARPROC function(LPCSTR) pfwglGetProcAddress;
164 typedef BOOL function(HDC, HGLRC) pfwglMakeCurrent;
165 typedef BOOL function(HDC, GLint, BOOL) pfwglRealizeLayerPalette;
166 typedef int function(HDC, GLint, GLint, GLint, COLORREF*) pfwglSetLayerPaletteEntries;
167 typedef BOOL function(HGLRC, HGLRC) pfwglShareLists;
168 typedef BOOL function(HDC, UINT) pfwglSwapLayerBuffers;
169 typedef BOOL function(HDC, DWORD, DWORD, DWORD) pfwglUseFontBitmapsA;
170 typedef BOOL function(HDC, DWORD, DWORD, DWORD) pfwglUseFontBitmapsW;
171 typedef BOOL function(HDC, DWORD, DWORD, DWORD, FLOAT, FLOAT, GLint, LPGLYPHMETRICSFLOAT) pfwglUseFontOutlinesA;
172 typedef BOOL function(HDC, DWORD, DWORD, DWORD, FLOAT, FLOAT, GLint, LPGLYPHMETRICSFLOAT) pfwglUseFontOutlinesW;
173
174 pfSwapBuffers           SwapBuffers;
175 pfwglCopyContext        wglCopyContext;
176 pfwglCreateContext      wglCreateContext;
177 pfwglCreateLayerContext     wglCreateLayerContext;
178 pfwglDeleteContext      wglDeleteContext;
179 pfwglDescribeLayerPlane     wglDescribeLayerPlane;
180 pfwglGetCurrentContext      wglGetCurrentContext;
181 pfwglGetCurrentDC       wglGetCurrentDC;
182 pfwglGetLayerPaletteEntries wglGetLayerPaletteEntries;
183 pfwglGetProcAddress     wglGetProcAddress;
184 pfwglMakeCurrent        wglMakeCurrent;
185 pfwglRealizeLayerPalette    wglRealizeLayerPalette;
186 pfwglSetLayerPaletteEntries wglSetLayerPaletteEntries;
187 pfwglShareLists         wglShareLists;
188 pfwglSwapLayerBuffers       wglSwapLayerBuffers;
189 pfwglUseFontBitmapsA        wglUseFontBitmapsA;
190 pfwglUseFontBitmapsW        wglUseFontBitmapsW;
191 pfwglUseFontOutlinesA       wglUseFontOutlinesA;
192 pfwglUseFontOutlinesW       wglUseFontOutlinesW;
193
194 version (UNICODE) {
195     alias wglUseFontBitmapsW  wglUseFontBitmaps;
196     alias wglUseFontOutlinesW wglUseFontOutlines;
197 } else {
198     alias wglUseFontBitmapsA  wglUseFontBitmaps;
199     alias wglUseFontOutlinesA wglUseFontOutlines;
200 }
201 }
Note: See TracBrowser for help on using the browser.