⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fxwgl.c

📁 winNT技术操作系统,国外开放的原代码和LIUX一样
💻 C
📖 第 1 页 / 共 3 页
字号:
      if (pfd.cAlphaBits > 0 && pix[i].pfd.cAlphaBits == 0)
         continue;              /* need alpha buffer */

#if 0                           /* regression bug? */
      if (pfd.cStencilBits > 0 && pix[i].pfd.cStencilBits == 0)
         continue;              /* need stencil buffer */
#endif

      if (pfd.iPixelType == pix[i].pfd.iPixelType) {
         best = i + 1;
         break;
      }
   }

   if (best == -1) {
      FILE *err = fopen("MESA.LOG", "w");
      if (err != NULL) {
         fprintf(err, "wglChoosePixelFormat failed\n");
         fprintf(err, "\tnSize           = %d\n", ppfd->nSize);
         fprintf(err, "\tnVersion        = %d\n", ppfd->nVersion);
         fprintf(err, "\tdwFlags         = %lu\n", ppfd->dwFlags);
         fprintf(err, "\tiPixelType      = %d\n", ppfd->iPixelType);
         fprintf(err, "\tcColorBits      = %d\n", ppfd->cColorBits);
         fprintf(err, "\tcRedBits        = %d\n", ppfd->cRedBits);
         fprintf(err, "\tcRedShift       = %d\n", ppfd->cRedShift);
         fprintf(err, "\tcGreenBits      = %d\n", ppfd->cGreenBits);
         fprintf(err, "\tcGreenShift     = %d\n", ppfd->cGreenShift);
         fprintf(err, "\tcBlueBits       = %d\n", ppfd->cBlueBits);
         fprintf(err, "\tcBlueShift      = %d\n", ppfd->cBlueShift);
         fprintf(err, "\tcAlphaBits      = %d\n", ppfd->cAlphaBits);
         fprintf(err, "\tcAlphaShift     = %d\n", ppfd->cAlphaShift);
         fprintf(err, "\tcAccumBits      = %d\n", ppfd->cAccumBits);
         fprintf(err, "\tcAccumRedBits   = %d\n", ppfd->cAccumRedBits);
         fprintf(err, "\tcAccumGreenBits = %d\n", ppfd->cAccumGreenBits);
         fprintf(err, "\tcAccumBlueBits  = %d\n", ppfd->cAccumBlueBits);
         fprintf(err, "\tcAccumAlphaBits = %d\n", ppfd->cAccumAlphaBits);
         fprintf(err, "\tcDepthBits      = %d\n", ppfd->cDepthBits);
         fprintf(err, "\tcStencilBits    = %d\n", ppfd->cStencilBits);
         fprintf(err, "\tcAuxBuffers     = %d\n", ppfd->cAuxBuffers);
         fprintf(err, "\tiLayerType      = %d\n", ppfd->iLayerType);
         fprintf(err, "\tbReserved       = %d\n", ppfd->bReserved);
         fprintf(err, "\tdwLayerMask     = %lu\n", ppfd->dwLayerMask);
         fprintf(err, "\tdwVisibleMask   = %lu\n", ppfd->dwVisibleMask);
         fprintf(err, "\tdwDamageMask    = %lu\n", ppfd->dwDamageMask);
         fclose(err);
      }

      SetLastError(0);
      return 0;
   }

   return best;
}

GLAPI int GLAPIENTRY
ChoosePixelFormat (HDC hdc, const PIXELFORMATDESCRIPTOR *ppfd)
{

   return wglChoosePixelFormat(hdc, ppfd);
}

GLAPI int GLAPIENTRY
wglDescribePixelFormat (HDC hdc, int iPixelFormat, UINT nBytes,
                        LPPIXELFORMATDESCRIPTOR ppfd)
{
   int qt_valid_pix;

   qt_valid_pix = pfd_tablen();

   if (iPixelFormat < 1 || iPixelFormat > qt_valid_pix ||
       ((nBytes != sizeof(PIXELFORMATDESCRIPTOR)) && (nBytes != 0))) {
      SetLastError(0);
      return qt_valid_pix;
   }

   if (nBytes != 0)
      *ppfd = pix[iPixelFormat - 1].pfd;

   return qt_valid_pix;
}

GLAPI int GLAPIENTRY
DescribePixelFormat (HDC hdc, int iPixelFormat, UINT nBytes,
                     LPPIXELFORMATDESCRIPTOR ppfd)
{
   return wglDescribePixelFormat(hdc, iPixelFormat, nBytes, ppfd);
}

GLAPI int GLAPIENTRY
wglGetPixelFormat (HDC hdc)
{
   if (curPFD == 0) {
      SetLastError(0);
      return 0;
   }

   return curPFD;
}

GLAPI int GLAPIENTRY
GetPixelFormat (HDC hdc)
{
   return wglGetPixelFormat(hdc);
}

GLAPI BOOL GLAPIENTRY
wglSetPixelFormat (HDC hdc, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
{
   int qt_valid_pix;

   qt_valid_pix = pfd_tablen();

   if (iPixelFormat < 1 || iPixelFormat > qt_valid_pix) {
      if (ppfd == NULL) {
         PIXELFORMATDESCRIPTOR my_pfd;
         if (!wglDescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &my_pfd)) {
            SetLastError(0);
            return FALSE;
         }
      } else if (ppfd->nSize != sizeof(PIXELFORMATDESCRIPTOR)) {
         SetLastError(0);
         return FALSE;
      }
   }
   curPFD = iPixelFormat;

   return TRUE;
}

GLAPI BOOL GLAPIENTRY
wglSwapBuffers (HDC hdc)
{
   if (!ctx) {
      SetLastError(0);
      return FALSE;
   }

   fxMesaSwapBuffers();

   return TRUE;
}

GLAPI BOOL GLAPIENTRY
SetPixelFormat (HDC hdc, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
{
   return wglSetPixelFormat(hdc, iPixelFormat, ppfd);
}

GLAPI BOOL GLAPIENTRY
SwapBuffers(HDC hdc)
{
   return wglSwapBuffers(hdc);
}

static FIXED
FixedFromDouble (double d)
{
   struct {
      FIXED f;
      long l;
   } pun;
   pun.l = (long)(d * 65536L);
   return pun.f;
}

/*
** This was yanked from windows/gdi/wgl.c
*/
GLAPI 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;

   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 < 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,        /* pointer 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;
}

GLAPI BOOL GLAPIENTRY
wglDescribeLayerPlane (HDC hdc, int iPixelFormat, int iLayerPlane,
                       UINT nBytes, LPLAYERPLANEDESCRIPTOR ppfd)
{
   SetLastError(0);
   return FALSE;
}

GLAPI int GLAPIENTRY
wglGetLayerPaletteEntries (HDC hdc, int iLayerPlane, int iStart,
                           int cEntries, COLORREF *pcr)
{
   SetLastError(0);
   return FALSE;
}

GLAPI BOOL GLAPIENTRY
wglRealizeLayerPalette (HDC hdc, int iLayerPlane, BOOL bRealize)
{
   SetLastError(0);
   return FALSE;
}

GLAPI int GLAPIENTRY
wglSetLayerPaletteEntries (HDC hdc, int iLayerPlane, int iStart,
                           int cEntries, CONST COLORREF *pcr)
{
   SetLastError(0);
   return FALSE;
}


/***************************************************************************
 * [dBorca] simplistic ICD implementation, based on ICD code by Gregor Anich
 */

typedef struct _icdTable {
   DWORD size;
   PROC table[336];
} ICDTABLE, *PICDTABLE;

#ifdef USE_MGL_NAMESPACE
#define GL_FUNC(func) mgl##func
#else
#define GL_FUNC(func) gl##func
#endif

static ICDTABLE icdTable = { 336, {
#define ICD_ENTRY(func) (PROC)GL_FUNC(func),
#include "../icd/icdlist.h"
#undef ICD_ENTRY
} };


GLAPI BOOL GLAPIENTRY
DrvCopyContext (HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
{
   return wglCopyContext(hglrcSrc, hglrcDst, mask);
}


GLAPI HGLRC GLAPIENTRY
DrvCreateContext (HDC hdc)
{
   return wglCreateContext(hdc);
}


GLAPI BOOL GLAPIENTRY
DrvDeleteContext (HGLRC hglrc)
{
   return wglDeleteContext(hglrc);
}


GLAPI HGLRC GLAPIENTRY
DrvCreateLayerContext (HDC hdc, int iLayerPlane)
{
   return wglCreateContext(hdc);
}


GLAPI PICDTABLE GLAPIENTRY
DrvSetContext (HDC hdc, HGLRC hglrc, void *callback)
{
   return wglMakeCurrent(hdc, hglrc) ? &icdTable : NULL;
}


GLAPI BOOL GLAPIENTRY
DrvReleaseContext (HGLRC hglrc)
{
   return TRUE;
}


GLAPI BOOL GLAPIENTRY
DrvShareLists (HGLRC hglrc1, HGLRC hglrc2)
{
   return wglShareLists(hglrc1, hglrc2);
}


GLAPI BOOL GLAPIENTRY
DrvDescribeLayerPlane (HDC hdc, int iPixelFormat,
                       int iLayerPlane, UINT nBytes,
                       LPLAYERPLANEDESCRIPTOR plpd)
{
   return wglDescribeLayerPlane(hdc, iPixelFormat, iLayerPlane, nBytes, plpd);
}


GLAPI int GLAPIENTRY
DrvSetLayerPaletteEntries (HDC hdc, int iLayerPlane,
                           int iStart, int cEntries, CONST COLORREF *pcr)
{
   return wglSetLayerPaletteEntries(hdc, iLayerPlane, iStart, cEntries, pcr);
}


GLAPI int GLAPIENTRY
DrvGetLayerPaletteEntries (HDC hdc, int iLayerPlane,
                           int iStart, int cEntries, COLORREF *pcr)
{
   return wglGetLayerPaletteEntries(hdc, iLayerPlane, iStart, cEntries, pcr);
}


GLAPI BOOL GLAPIENTRY
DrvRealizeLayerPalette (HDC hdc, int iLayerPlane, BOOL bRealize)
{
   return wglRealizeLayerPalette(hdc, iLayerPlane, bRealize);
}


GLAPI BOOL GLAPIENTRY
DrvSwapLayerBuffers (HDC hdc, UINT fuPlanes)
{
   return wglSwapLayerBuffers(hdc, fuPlanes);
}

GLAPI int GLAPIENTRY
DrvDescribePixelFormat (HDC hdc, int iPixelFormat, UINT nBytes,
                        LPPIXELFORMATDESCRIPTOR ppfd)
{
   return wglDescribePixelFormat(hdc, iPixelFormat, nBytes, ppfd);
}


GLAPI PROC GLAPIENTRY
DrvGetProcAddress (LPCSTR lpszProc)
{
   return wglGetProcAddress(lpszProc);
}


GLAPI BOOL GLAPIENTRY
DrvSetPixelFormat (HDC hdc, int iPixelFormat)
{
   return wglSetPixelFormat(hdc, iPixelFormat, NULL);
}


GLAPI BOOL GLAPIENTRY
DrvSwapBuffers (HDC hdc)
{
   return wglSwapBuffers(hdc);
}


GLAPI BOOL GLAPIENTRY
DrvValidateVersion (DWORD version)
{
   (void)version;
   return TRUE;
}


#if (_MSC_VER >= 1200)
#pragma warning( pop )
#endif

#endif /* FX */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -