📄 fxwgl.c
字号:
}
GLAPI int GLAPIENTRY
wglGetSwapIntervalEXT (void)
{
return (ctx == NULL) ? -1 : ctx->swapInterval;
}
GLAPI BOOL GLAPIENTRY
wglGetDeviceGammaRamp3DFX (HDC hdc, LPVOID arrays)
{
/* gammaTable should be per-context */
memcpy(arrays, gammaTable, 3 * 256 * sizeof(GLushort));
return TRUE;
}
GLAPI BOOL GLAPIENTRY
wglSetDeviceGammaRamp3DFX (HDC hdc, LPVOID arrays)
{
GLint i, tableSize, inc, index;
GLushort *red, *green, *blue;
FxU32 gammaTableR[256], gammaTableG[256], gammaTableB[256];
/* gammaTable should be per-context */
memcpy(gammaTable, arrays, 3 * 256 * sizeof(GLushort));
tableSize = FX_grGetInteger(GR_GAMMA_TABLE_ENTRIES);
inc = 256 / tableSize;
red = (GLushort *)arrays;
green = (GLushort *)arrays + 256;
blue = (GLushort *)arrays + 512;
for (i = 0, index = 0; i < tableSize; i++, index += inc) {
gammaTableR[i] = red[index] >> 8;
gammaTableG[i] = green[index] >> 8;
gammaTableB[i] = blue[index] >> 8;
}
grLoadGammaTable(tableSize, gammaTableR, gammaTableG, gammaTableB);
return TRUE;
}
typedef void *HPBUFFERARB;
/* WGL_ARB_pixel_format */
GLAPI BOOL GLAPIENTRY
wglGetPixelFormatAttribivARB (HDC hdc,
int iPixelFormat,
int iLayerPlane,
UINT nAttributes,
const int *piAttributes,
int *piValues)
{
SetLastError(0);
return FALSE;
}
GLAPI BOOL GLAPIENTRY
wglGetPixelFormatAttribfvARB (HDC hdc,
int iPixelFormat,
int iLayerPlane,
UINT nAttributes,
const int *piAttributes,
FLOAT *pfValues)
{
SetLastError(0);
return FALSE;
}
GLAPI BOOL GLAPIENTRY
wglChoosePixelFormatARB (HDC hdc,
const int *piAttribIList,
const FLOAT *pfAttribFList,
UINT nMaxFormats,
int *piFormats,
UINT *nNumFormats)
{
SetLastError(0);
return FALSE;
}
/* WGL_ARB_render_texture */
GLAPI BOOL GLAPIENTRY
wglBindTexImageARB (HPBUFFERARB hPbuffer, int iBuffer)
{
SetLastError(0);
return FALSE;
}
GLAPI BOOL GLAPIENTRY
wglReleaseTexImageARB (HPBUFFERARB hPbuffer, int iBuffer)
{
SetLastError(0);
return FALSE;
}
GLAPI BOOL GLAPIENTRY
wglSetPbufferAttribARB (HPBUFFERARB hPbuffer,
const int *piAttribList)
{
SetLastError(0);
return FALSE;
}
/* WGL_ARB_pbuffer */
GLAPI HPBUFFERARB GLAPIENTRY
wglCreatePbufferARB (HDC hDC,
int iPixelFormat,
int iWidth,
int iHeight,
const int *piAttribList)
{
SetLastError(0);
return NULL;
}
GLAPI HDC GLAPIENTRY
wglGetPbufferDCARB (HPBUFFERARB hPbuffer)
{
SetLastError(0);
return NULL;
}
GLAPI int GLAPIENTRY
wglReleasePbufferDCARB (HPBUFFERARB hPbuffer, HDC hDC)
{
SetLastError(0);
return -1;
}
GLAPI BOOL GLAPIENTRY
wglDestroyPbufferARB (HPBUFFERARB hPbuffer)
{
SetLastError(0);
return FALSE;
}
GLAPI BOOL GLAPIENTRY
wglQueryPbufferARB (HPBUFFERARB hPbuffer,
int iAttribute,
int *piValue)
{
SetLastError(0);
return FALSE;
}
GLAPI const char * GLAPIENTRY
wglGetExtensionsStringEXT (void)
{
return "WGL_3DFX_gamma_control "
"WGL_EXT_swap_control "
"WGL_EXT_extensions_string WGL_ARB_extensions_string"
/*WGL_ARB_pixel_format WGL_ARB_render_texture WGL_ARB_pbuffer*/;
}
GLAPI const char * GLAPIENTRY
wglGetExtensionsStringARB (HDC hdc)
{
return wglGetExtensionsStringEXT();
}
static struct {
const char *name;
PROC func;
} wgl_ext[] = {
{"wglGetExtensionsStringARB", (PROC)wglGetExtensionsStringARB},
{"wglGetExtensionsStringEXT", (PROC)wglGetExtensionsStringEXT},
{"wglSwapIntervalEXT", (PROC)wglSwapIntervalEXT},
{"wglGetSwapIntervalEXT", (PROC)wglGetSwapIntervalEXT},
{"wglGetDeviceGammaRamp3DFX", (PROC)wglGetDeviceGammaRamp3DFX},
{"wglSetDeviceGammaRamp3DFX", (PROC)wglSetDeviceGammaRamp3DFX},
/* WGL_ARB_pixel_format */
{"wglGetPixelFormatAttribivARB", (PROC)wglGetPixelFormatAttribivARB},
{"wglGetPixelFormatAttribfvARB", (PROC)wglGetPixelFormatAttribfvARB},
{"wglChoosePixelFormatARB", (PROC)wglChoosePixelFormatARB},
/* WGL_ARB_render_texture */
{"wglBindTexImageARB", (PROC)wglBindTexImageARB},
{"wglReleaseTexImageARB", (PROC)wglReleaseTexImageARB},
{"wglSetPbufferAttribARB", (PROC)wglSetPbufferAttribARB},
/* WGL_ARB_pbuffer */
{"wglCreatePbufferARB", (PROC)wglCreatePbufferARB},
{"wglGetPbufferDCARB", (PROC)wglGetPbufferDCARB},
{"wglReleasePbufferDCARB", (PROC)wglReleasePbufferDCARB},
{"wglDestroyPbufferARB", (PROC)wglDestroyPbufferARB},
{"wglQueryPbufferARB", (PROC)wglQueryPbufferARB},
{NULL, NULL}
};
GLAPI PROC GLAPIENTRY
wglGetProcAddress (LPCSTR lpszProc)
{
int i;
PROC p = (PROC)_glapi_get_proc_address((const char *)lpszProc);
/* we can't BlendColor. work around buggy applications */
if (p && strcmp(lpszProc, "glBlendColor")
&& strcmp(lpszProc, "glBlendColorEXT"))
return p;
for (i = 0; wgl_ext[i].name; i++) {
if (!strcmp(lpszProc, wgl_ext[i].name)) {
return wgl_ext[i].func;
}
}
SetLastError(0);
return NULL;
}
GLAPI PROC GLAPIENTRY
wglGetDefaultProcAddress (LPCSTR lpszProc)
{
SetLastError(0);
return NULL;
}
GLAPI BOOL GLAPIENTRY
wglMakeCurrent (HDC hdc, HGLRC hglrc)
{
if ((hdc == NULL) && (hglrc == NULL))
return TRUE;
if (!ctx || hglrc != (HGLRC)1 || WindowFromDC(hdc) != hWND) {
SetLastError(0);
return FALSE;
}
hDC = hdc;
fxMesaMakeCurrent(ctx);
return TRUE;
}
GLAPI BOOL GLAPIENTRY
wglShareLists (HGLRC hglrc1, HGLRC hglrc2)
{
if (!ctx || hglrc1 != (HGLRC)1 || hglrc1 != hglrc2) {
SetLastError(0);
return FALSE;
}
return TRUE;
}
static BOOL
wglUseFontBitmaps_FX (HDC fontDevice, DWORD firstChar, DWORD numChars,
DWORD listBase)
{
TEXTMETRIC metric;
BITMAPINFO *dibInfo;
HDC bitDevice;
COLORREF tempColor;
int i;
GetTextMetrics(fontDevice, &metric);
dibInfo = (BITMAPINFO *)calloc(sizeof(BITMAPINFO) + sizeof(RGBQUAD), 1);
dibInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
dibInfo->bmiHeader.biPlanes = 1;
dibInfo->bmiHeader.biBitCount = 1;
dibInfo->bmiHeader.biCompression = BI_RGB;
bitDevice = CreateCompatibleDC(fontDevice);
/* Swap fore and back colors so the bitmap has the right polarity */
tempColor = GetBkColor(bitDevice);
SetBkColor(bitDevice, GetTextColor(bitDevice));
SetTextColor(bitDevice, tempColor);
/* Place chars based on base line */
SetTextAlign(bitDevice, TA_BASELINE);
for (i = 0; i < (int)numChars; i++) {
SIZE size;
char curChar;
int charWidth, charHeight, bmapWidth, bmapHeight, numBytes, res;
HBITMAP bitObject;
HGDIOBJ origBmap;
unsigned char *bmap;
curChar = (char)(i + firstChar); /* [koolsmoky] explicit cast */
/* Find how high/wide this character is */
GetTextExtentPoint32(bitDevice, &curChar, 1, &size);
/* Create the output bitmap */
charWidth = size.cx;
charHeight = size.cy;
bmapWidth = ((charWidth + 31) / 32) * 32; /* Round up to the next multiple of 32 bits */
bmapHeight = charHeight;
bitObject = CreateCompatibleBitmap(bitDevice, bmapWidth, bmapHeight);
/*VERIFY(bitObject);*/
/* Assign the output bitmap to the device */
origBmap = SelectObject(bitDevice, bitObject);
PatBlt(bitDevice, 0, 0, bmapWidth, bmapHeight, BLACKNESS);
/* Use our source font on the device */
SelectObject(bitDevice, GetCurrentObject(fontDevice, OBJ_FONT));
/* Draw the character */
TextOut(bitDevice, 0, metric.tmAscent, &curChar, 1);
/* Unselect our bmap object */
SelectObject(bitDevice, origBmap);
/* Convert the display dependant representation to a 1 bit deep DIB */
numBytes = (bmapWidth * bmapHeight) / 8;
bmap = MALLOC(numBytes);
dibInfo->bmiHeader.biWidth = bmapWidth;
dibInfo->bmiHeader.biHeight = bmapHeight;
res = GetDIBits(bitDevice, bitObject, 0, bmapHeight, bmap,
dibInfo, DIB_RGB_COLORS);
/* Create the GL object */
glNewList(i + listBase, GL_COMPILE);
glBitmap(bmapWidth, bmapHeight, 0.0, metric.tmDescent,
charWidth, 0.0, bmap);
glEndList();
/* CheckGL(); */
/* Destroy the bmap object */
DeleteObject(bitObject);
/* Deallocate the bitmap data */
FREE(bmap);
}
/* Destroy the DC */
DeleteDC(bitDevice);
FREE(dibInfo);
return TRUE;
}
GLAPI BOOL GLAPIENTRY
wglUseFontBitmapsW (HDC hdc, DWORD first, DWORD count, DWORD listBase)
{
return FALSE;
}
GLAPI BOOL GLAPIENTRY
wglUseFontOutlinesA (HDC hdc, DWORD first, DWORD count,
DWORD listBase, FLOAT deviation,
FLOAT extrusion, int format, LPGLYPHMETRICSFLOAT lpgmf)
{
SetLastError(0);
return FALSE;
}
GLAPI BOOL GLAPIENTRY
wglUseFontOutlinesW (HDC hdc, DWORD first, DWORD count,
DWORD listBase, FLOAT deviation,
FLOAT extrusion, int format, LPGLYPHMETRICSFLOAT lpgmf)
{
SetLastError(0);
return FALSE;
}
GLAPI BOOL GLAPIENTRY
wglSwapLayerBuffers (HDC hdc, UINT fuPlanes)
{
if (ctx && WindowFromDC(hdc) == hWND) {
fxMesaSwapBuffers();
return TRUE;
}
SetLastError(0);
return FALSE;
}
static int
pfd_tablen (void)
{
/* we should take an envvar for `fxMesaSelectCurrentBoard' */
return (fxMesaSelectCurrentBoard(0) < GR_SSTTYPE_Voodoo4)
? 2 /* only 16bit entries */
: sizeof(pix) / sizeof(pix[0]); /* full table */
}
GLAPI int GLAPIENTRY
wglChoosePixelFormat (HDC hdc, const PIXELFORMATDESCRIPTOR *ppfd)
{
int i, best = -1, qt_valid_pix;
PIXELFORMATDESCRIPTOR pfd = *ppfd;
qt_valid_pix = pfd_tablen();
#if 1 || QUAKE2 || GORE
/* QUAKE2: 24+32 */
/* GORE : 24+16 */
if ((pfd.cColorBits == 24) || (pfd.cColorBits == 32)) {
/* the first 2 entries are 16bit */
pfd.cColorBits = (qt_valid_pix > 2) ? 32 : 16;
}
if (pfd.cColorBits == 32) {
pfd.cDepthBits = 24;
} else if (pfd.cColorBits == 16) {
pfd.cDepthBits = 16;
}
#endif
if (pfd.nSize != sizeof(PIXELFORMATDESCRIPTOR) || pfd.nVersion != 1) {
SetLastError(0);
return 0;
}
for (i = 0; i < qt_valid_pix; i++) {
if (pfd.cColorBits > 0 && pix[i].pfd.cColorBits != pfd.cColorBits)
continue;
if ((pfd.dwFlags & PFD_DRAW_TO_WINDOW)
&& !(pix[i].pfd.dwFlags & PFD_DRAW_TO_WINDOW)) continue;
if ((pfd.dwFlags & PFD_DRAW_TO_BITMAP)
&& !(pix[i].pfd.dwFlags & PFD_DRAW_TO_BITMAP)) continue;
if ((pfd.dwFlags & PFD_SUPPORT_GDI)
&& !(pix[i].pfd.dwFlags & PFD_SUPPORT_GDI)) continue;
if ((pfd.dwFlags & PFD_SUPPORT_OPENGL)
&& !(pix[i].pfd.dwFlags & PFD_SUPPORT_OPENGL)) continue;
if (!(pfd.dwFlags & PFD_DOUBLEBUFFER_DONTCARE)
&& ((pfd.dwFlags & PFD_DOUBLEBUFFER) !=
(pix[i].pfd.dwFlags & PFD_DOUBLEBUFFER))) continue;
#if 1 /* Doom3 fails here! */
if (!(pfd.dwFlags & PFD_STEREO_DONTCARE)
&& ((pfd.dwFlags & PFD_STEREO) !=
(pix[i].pfd.dwFlags & PFD_STEREO))) continue;
#endif
if (pfd.cDepthBits > 0 && pix[i].pfd.cDepthBits == 0)
continue; /* need depth buffer */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -