[Mesa-dev] [PATCH] wgl: Rudimentary wglUseFontBitmaps sample.

Brian Paul brianp at vmware.com
Wed Jan 6 08:29:20 PST 2016


The copyright line could be bumped to 2016.

Reviewed-by: Brian Paul <brianp at vmware.com>

On 01/06/2016 09:21 AM, Jose Fonseca wrote:
> It uses SYSTEM_FONT which actually creates some challenges when emulating
> wglUseFontBitmaps:  in spite what https://msdn.microsoft.com/en-us/library/windows/desktop/dd374392.aspx
> implies, GetGlyphOutline(GGO_BITMAP) does not seem to work with certain
> fonts.  The only solution is to draw the font charactors with a HBITMAP
> like the old Mesa fxwgl.c code used to do.  That too, seems to be the way
> that opengl32.dll implements wglUseFontBitmaps.
> ---
>   src/wgl/CMakeLists.txt |   2 +
>   src/wgl/wglfont.c      | 103 +++++++++++++++++++++++++++++++++++++++++++++++++
>   2 files changed, 105 insertions(+)
>   create mode 100644 src/wgl/wglfont.c
>
> diff --git a/src/wgl/CMakeLists.txt b/src/wgl/CMakeLists.txt
> index 0229ac7..cb50cca 100644
> --- a/src/wgl/CMakeLists.txt
> +++ b/src/wgl/CMakeLists.txt
> @@ -16,6 +16,7 @@ set_target_properties (wgl_sharedtex_mt PROPERTIES OUTPUT_NAME sharedtex_mt)
>   add_executable (wglinfo wglinfo.c ${CMAKE_SOURCE_DIR}/src/xdemos/glinfo_common.c)
>   add_executable (wglcontext wglcontext.c)
>   add_executable (wincopy WIN32 wincopy.c wglutil.c)
> +add_executable (wglfont wglfont.c)
>
>   install (
>   	TARGETS
> @@ -23,6 +24,7 @@ install (
>   		wgl_sharedtex_mt
>   		wglinfo
>   		wglcontext
> +		wglfont
>   		wincopy
>   	DESTINATION wgl)
>
> diff --git a/src/wgl/wglfont.c b/src/wgl/wglfont.c
> new file mode 100644
> index 0000000..86c5f88
> --- /dev/null
> +++ b/src/wgl/wglfont.c
> @@ -0,0 +1,103 @@
> +/*
> + * Copyright (C) 2015, VMware, Inc.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included
> + * in all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
> + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
> + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
> + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#include <windows.h>
> +#include <stdlib.h>
> +#include <GL/gl.h>
> +
> +int
> +main(int argc, char *argv[])
> +{
> +   WNDCLASS wc;
> +   HWND hwnd;
> +   HDC hdc;
> +   PIXELFORMATDESCRIPTOR pfd;
> +   int iPixelFormat;
> +   HGLRC hglrc;
> +
> +   ZeroMemory(&wc, sizeof wc);
> +   wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
> +   wc.lpfnWndProc = DefWindowProc;
> +   wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
> +   wc.hCursor = LoadCursor(NULL, IDC_ARROW);
> +   wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
> +   wc.lpszClassName = "wglfont";
> +
> +   if (!RegisterClass(&wc)) {
> +      abort();
> +   }
> +
> +   hwnd = CreateWindowEx(0,
> +                         wc.lpszClassName,
> +                         "wglfont",
> +                         WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TILEDWINDOW,
> +                         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
> +                         NULL, NULL,
> +                         wc.hInstance,
> +                         NULL);
> +   if (!hwnd) {
> +      abort();
> +   }
> +
> +   hdc = GetDC(hwnd);
> +   if (!hdc) {
> +      abort();
> +   }
> +
> +   ZeroMemory(&pfd, sizeof pfd);
> +   pfd.nSize = sizeof pfd;
> +   pfd.nVersion = 1;
> +   pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
> +   pfd.iPixelType = PFD_TYPE_RGBA;
> +   pfd.cColorBits = 24;
> +   pfd.cDepthBits = 24;
> +   pfd.iLayerType = PFD_MAIN_PLANE;
> +
> +   iPixelFormat = ChoosePixelFormat(hdc, &pfd);
> +   if (!iPixelFormat) {
> +      abort();
> +   }
> +
> +   if (!SetPixelFormat(hdc, iPixelFormat, &pfd)) {
> +      abort();
> +   }
> +
> +   hglrc = wglCreateContext(hdc);
> +   if (!hglrc) {
> +      abort();
> +   }
> +
> +   wglMakeCurrent(hdc, hglrc);
> +
> +   SelectObject(hdc, GetStockObject(SYSTEM_FONT));
> +
> +   wglUseFontBitmaps(hdc, 0, 255, 1000);
> +
> +   glListBase(1000);
> +
> +   glCallLists(12, GL_UNSIGNED_BYTE, "Hello World!");
> +
> +   SwapBuffers(hdc);
> +
> +   Sleep(1000);
> +
> +   return 0;
> +}
>



More information about the mesa-dev mailing list