summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose Fonseca <jfonseca@vmware.com>2016-01-06 16:18:36 +0000
committerJose Fonseca <jfonseca@vmware.com>2016-01-06 16:32:32 +0000
commit1815f0bb6e1a20dcc768bc69f4e94aa76c42539f (patch)
treebc4863a569fc41303175bcbb87c0f8df1eb2a7e1
parent0a8779daf6d651f3264dfe0168e92ab2c61a9a67 (diff)
downloadmesa-demos-1815f0bb6e1a20dcc768bc69f4e94aa76c42539f.zip
mesa-demos-1815f0bb6e1a20dcc768bc69f4e94aa76c42539f.tar.xz
wgl: Rudimentary wglUseFontBitmaps sample.
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. Reviewed-by: Brian Paul <brianp@vmware.com>
-rw-r--r--src/wgl/CMakeLists.txt2
-rw-r--r--src/wgl/wglfont.c103
2 files changed, 105 insertions, 0 deletions
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..2e448ec
--- /dev/null
+++ b/src/wgl/wglfont.c
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2016, 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;
+}