📄 wgl.c
字号:
ppfd->nSize != sizeof(PIXELFORMATDESCRIPTOR)) {
SetLastError(0);
return(FALSE);
}
curPFD = iPixelFormat;
return(TRUE);
}
WINGDIAPI BOOL GLAPIENTRY wglSwapBuffers(HDC hdc)
{
(void) hdc;
if (ctx_current < 0)
return FALSE;
if(wgl_ctx[ctx_current].ctx == NULL) {
SetLastError(0);
return(FALSE);
}
WMesaSwapBuffers();
return(TRUE);
}
static FIXED FixedFromDouble(double d)
{
long l = (long) (d * 65536L);
return *(FIXED *) (void *) &l;
}
/*
** This is cribbed from FX/fxwgl.c, and seems to implement support
** for bitmap fonts where the wglUseFontBitmapsA() code implements
** support for outline fonts. In combination they hopefully give
** fairly generic support for fonts.
*/
static BOOL wglUseFontBitmaps_FX(HDC fontDevice, DWORD firstChar,
DWORD numChars, DWORD listBase)
{
#define VERIFY(a) a
TEXTMETRIC metric;
BITMAPINFO *dibInfo;
HDC bitDevice;
COLORREF tempColor;
int i;
VERIFY(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
VERIFY(SetTextAlign(bitDevice, TA_BASELINE) != GDI_ERROR ? 1 : 0);
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 = i + firstChar;
// Find how high/wide this character is
VERIFY(GetTextExtentPoint32(bitDevice, &curChar, 1, &size));
// Create the output bitmap
charWidth = size.cx;
charHeight = size.cy;
// Round up to the next multiple of 32 bits
bmapWidth = ((charWidth + 31) / 32) * 32;
bmapHeight = charHeight;
bitObject = CreateCompatibleBitmap(bitDevice,
bmapWidth,
bmapHeight);
//VERIFY(bitObject);
// Assign the output bitmap to the device
origBmap = SelectObject(bitDevice, bitObject);
(void) VERIFY(origBmap);
VERIFY( PatBlt( bitDevice, 0, 0, bmapWidth, bmapHeight,BLACKNESS ) );
// Use our source font on the device
VERIFY(SelectObject(bitDevice, GetCurrentObject(fontDevice,OBJ_FONT)));
// Draw the character
VERIFY(TextOut(bitDevice, 0, metric.tmAscent, &curChar, 1));
// Unselect our bmap object
VERIFY(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);
//VERIFY(res);
// 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
VERIFY(DeleteDC(bitDevice));
free(dibInfo);
return TRUE;
#undef VERIFY
}
WINGDIAPI BOOL GLAPIENTRY wglUseFontBitmapsA(HDC hdc, DWORD first,
DWORD count, DWORD listBase)
{
int i;
GLuint font_list;
DWORD size;
GLYPHMETRICS gm;
HANDLE hBits;
LPSTR lpBits;
MAT2 mat;
int success = TRUE;
if (count == 0)
return FALSE;
font_list = listBase;
mat.eM11 = FixedFromDouble(1);
mat.eM12 = FixedFromDouble(0);
mat.eM21 = FixedFromDouble(0);
mat.eM22 = FixedFromDouble(-1);
memset(&gm,0,sizeof(gm));
/*
** If we can't get the glyph outline, it may be because this is a fixed
** font. Try processing it that way.
*/
if( GetGlyphOutline(hdc, first, GGO_BITMAP, &gm, 0, NULL, &mat)
== GDI_ERROR ) {
return wglUseFontBitmaps_FX( hdc, first, count, listBase );
}
/*
** Otherwise process all desired characters.
*/
for (i = 0; i < (int)count; i++) {
DWORD err;
glNewList( font_list+i, GL_COMPILE );
/* allocate space for the bitmap/outline */
size = GetGlyphOutline(hdc, first + i, GGO_BITMAP,
&gm, 0, NULL, &mat);
if (size == GDI_ERROR) {
glEndList( );
err = GetLastError();
success = FALSE;
continue;
}
hBits = GlobalAlloc(GHND, size+1);
lpBits = GlobalLock(hBits);
err =
GetGlyphOutline(hdc, /* handle to device context */
first + i, /* character to query */
GGO_BITMAP, /* format of data to return */
&gm, /* ptr to structure for metrics*/
size, /* size of buffer for data */
lpBits, /* pointer to buffer for data */
&mat /* pointer to transformation */
/* matrix structure */
);
if (err == GDI_ERROR) {
GlobalUnlock(hBits);
GlobalFree(hBits);
glEndList( );
err = GetLastError();
success = FALSE;
continue;
}
glBitmap(gm.gmBlackBoxX,gm.gmBlackBoxY,
-gm.gmptGlyphOrigin.x,
gm.gmptGlyphOrigin.y,
gm.gmCellIncX,gm.gmCellIncY,
(const GLubyte * )lpBits);
GlobalUnlock(hBits);
GlobalFree(hBits);
glEndList( );
}
return success;
}
/* NOT IMPLEMENTED YET */
WINGDIAPI BOOL GLAPIENTRY wglCopyContext(HGLRC hglrcSrc,
HGLRC hglrcDst,
UINT mask)
{
(void) hglrcSrc; (void) hglrcDst; (void) mask;
return(FALSE);
}
WINGDIAPI HGLRC GLAPIENTRY wglCreateLayerContext(HDC hdc,
int iLayerPlane)
{
(void) hdc; (void) iLayerPlane;
SetLastError(0);
return(NULL);
}
WINGDIAPI BOOL GLAPIENTRY wglShareLists(HGLRC hglrc1,
HGLRC hglrc2)
{
(void) hglrc1; (void) hglrc2;
return(TRUE);
}
WINGDIAPI BOOL GLAPIENTRY wglUseFontBitmapsW(HDC hdc,
DWORD first,
DWORD count,
DWORD listBase)
{
(void) hdc; (void) first; (void) count; (void) listBase;
return FALSE;
}
WINGDIAPI BOOL GLAPIENTRY wglUseFontOutlinesA(HDC hdc,
DWORD first,
DWORD count,
DWORD listBase,
FLOAT deviation,
FLOAT extrusion,
int format,
LPGLYPHMETRICSFLOAT lpgmf)
{
(void) hdc; (void) first; (void) count;
(void) listBase; (void) deviation; (void) extrusion; (void) format;
(void) lpgmf;
SetLastError(0);
return(FALSE);
}
WINGDIAPI BOOL GLAPIENTRY wglUseFontOutlinesW(HDC hdc,
DWORD first,
DWORD count,
DWORD listBase,
FLOAT deviation,
FLOAT extrusion,
int format,
LPGLYPHMETRICSFLOAT lpgmf)
{
(void) hdc; (void) first; (void) count;
(void) listBase; (void) deviation; (void) extrusion; (void) format;
(void) lpgmf;
SetLastError(0);
return(FALSE);
}
WINGDIAPI BOOL GLAPIENTRY wglDescribeLayerPlane(HDC hdc,
int iPixelFormat,
int iLayerPlane,
UINT nBytes,
LPLAYERPLANEDESCRIPTOR plpd)
{
(void) hdc; (void) iPixelFormat; (void) iLayerPlane;
(void) nBytes; (void) plpd;
SetLastError(0);
return(FALSE);
}
WINGDIAPI int GLAPIENTRY wglSetLayerPaletteEntries(HDC hdc,
int iLayerPlane,
int iStart,
int cEntries,
CONST COLORREF *pcr)
{
(void) hdc; (void) iLayerPlane; (void) iStart;
(void) cEntries; (void) pcr;
SetLastError(0);
return(0);
}
WINGDIAPI int GLAPIENTRY wglGetLayerPaletteEntries(HDC hdc,
int iLayerPlane,
int iStart,
int cEntries,
COLORREF *pcr)
{
(void) hdc; (void) iLayerPlane; (void) iStart; (void) cEntries; (void) pcr;
SetLastError(0);
return(0);
}
WINGDIAPI BOOL GLAPIENTRY wglRealizeLayerPalette(HDC hdc,
int iLayerPlane,
BOOL bRealize)
{
(void) hdc; (void) iLayerPlane; (void) bRealize;
SetLastError(0);
return(FALSE);
}
WINGDIAPI BOOL GLAPIENTRY wglSwapLayerBuffers(HDC hdc,
UINT fuPlanes)
{
(void) hdc; (void) fuPlanes;
SetLastError(0);
return(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -