Mercurial > projects > mde
annotate mde/font/FontTexture.d @ 98:49e7cfed4b34
All types of Option have been converted to use ValueContent classes, and their values can be displayed.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Wed, 12 Nov 2008 13:18:51 +0000 |
parents | 30470bc19ca4 |
children | 0ea4a3e651ae |
rev | line source |
---|---|
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
1 /* LICENSE BLOCK |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
3 Copyright © 2007-2008 Diggory Hardy |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
4 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify it under the terms |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
6 of the GNU General Public License as published by the Free Software Foundation, either |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
7 version 2 of the License, or (at your option) any later version. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
8 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
11 See the GNU General Public License for more details. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
12 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
15 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
16 /** Font caching system. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
17 * |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
49
diff
changeset
|
18 * This module also serves as the internals to the font module and shouldn't be used except through |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
49
diff
changeset
|
19 * the font module. The two modules could be combined, at a cost to readability. |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
49
diff
changeset
|
20 * |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
21 * Three types of coordinates get used in the system: FreeType coordinates for each glyph, texture |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
22 * coordinates, and OpenGL's model/world coordinates (for rendering). The freetype and texture |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
23 * coords are cartesian (i.e. y increases upwards), although largely this is too abstract to |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
24 * matter. However, for the model/world coords, y increases downwards. */ |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
61
diff
changeset
|
25 module mde.font.FontTexture; |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
26 |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
61
diff
changeset
|
27 import mde.types.Colour; |
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
61
diff
changeset
|
28 import mde.lookup.Options; |
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
61
diff
changeset
|
29 import mde.font.exception; |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
30 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
31 import derelict.freetype.ft; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
32 import derelict.opengl.gl; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
33 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
34 import Utf = tango.text.convert.Utf; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
35 import tango.util.log.Log : Log, Logger; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
36 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
37 private Logger logger; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
38 static this () { |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
61
diff
changeset
|
39 logger = Log.getLogger ("mde.font.FontTexture"); |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
40 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
41 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
42 static const int dimW = 256, dimH = 256; // Texture size |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
43 const wFactor = 1f / dimW; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
44 const hFactor = 1f / dimH; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
45 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
46 /** A FontTexture is basically a cache of all font glyphs rendered so far. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
47 * |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
48 * This class should be limited to code for rendering to (and otherwise handling) textures and |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
49 * rendering fonts to the screen. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
50 * |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
51 * Technically, there's no reason it shouldn't be a static part of the FontStyle class. */ |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
52 class FontTexture |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
53 { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
54 // Call if font(s) have been changed and glyphs must be recached. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
55 void clear () { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
56 foreach (t; tex) { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
57 glDeleteTextures (1, &(t.texID)); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
58 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
59 cachedGlyphs = null; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
60 ++cacheVer; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
61 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
62 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
63 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
64 /** Cache informatation for rendering a block of text. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
65 * |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
66 * Recognises '\r', '\n' and "\r\n" as end-of-line markers. */ |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
67 void updateCache (FT_Face face, char[] str, ref TextBlock cache) |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
68 { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
69 debug scope (failure) |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
51
diff
changeset
|
70 logger.error ("updateCache failed"); |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
71 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
72 if (cache.cacheVer == cacheVer) // Existing cache is up-to-date |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
73 return; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
74 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
75 cache.cacheVer = cacheVer; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
76 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
77 /* Convert the string to an array of character codes (which is equivalent to decoding UTF8 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
78 * to UTF32 since no character code is ever > dchar.max). */ |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
79 static dchar[] chrs; // keep memory for future calls (NOTE: change for threading) |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
80 chrs = Utf.toString32 (str, chrs); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
81 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
82 // Allocate space. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
83 // Since end-of-line chars get excluded, will often be slightly larger than necessary. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
84 cache.chars.length = chrs.length; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
85 cache.chars.length = 0; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
86 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
87 int lineSep = face.size.metrics.height >> 6; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
88 bool hasKerning = (FT_HAS_KERNING (face) != 0); |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
89 int y = face.size.metrics.ascender >> 6; |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
90 CharCache cc; // struct; reused for each character |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
91 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
92 for (size_t i = 0; i < chrs.length; ++i) |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
93 { |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
94 // For each line: |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
95 int x = 0; // x pos for next glyph |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
96 uint gi_prev = 0; // previous glyph index (needed for kerning) |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
97 |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
98 for (; i < chrs.length; ++i) |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
99 { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
100 // If end-of-line, break to find yMax for next line. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
101 if (chrs.length >= i+2 && chrs[i..i+2] == "\r\n"d) { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
102 ++i; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
103 break; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
104 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
105 if (chrs[i] == '\n' || chrs[i] == '\r') { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
106 break; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
107 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
108 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
109 cc.ga = chrs[i] in cachedGlyphs; |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
110 if (cc.ga is null) { // Not cached |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
111 addGlyph (face, chrs[i]); // so render it |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
112 cc.ga = chrs[i] in cachedGlyphs; // get the ref of the copy we've stored |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
113 assert (cc.ga !is null, "Unable to cache glyph!"); |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
114 } |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
115 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
116 // Kerning |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
117 if (hasKerning && (gi_prev != 0)) { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
118 FT_Vector delta; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
119 FT_Get_Kerning (face, gi_prev, cc.ga.index, FT_Kerning_Mode.FT_KERNING_DEFAULT, &delta); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
120 x += delta.x >> 6; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
121 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
122 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
123 // ga.left component: adding this slightly improves glyph layout. Note that the |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
124 // left-most glyph on a line may not start right on the edge, but this looks best. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
125 cc.xPos = x + cc.ga.left; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
126 cc.yPos = y - cc.ga.top; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
127 x += cc.ga.advanceX; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
128 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
129 cache.chars ~= cc; |
49
bca7e2342d77
Enabled getting the size of a text block (before or after rendering).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
48
diff
changeset
|
130 |
bca7e2342d77
Enabled getting the size of a text block (before or after rendering).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
48
diff
changeset
|
131 // Update rect total size. Top and left coords should be zero, so make width and |
bca7e2342d77
Enabled getting the size of a text block (before or after rendering).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
48
diff
changeset
|
132 // height maximal x and y coordinates. |
bca7e2342d77
Enabled getting the size of a text block (before or after rendering).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
48
diff
changeset
|
133 if (cc.xPos + cc.ga.w > cache.w) |
bca7e2342d77
Enabled getting the size of a text block (before or after rendering).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
48
diff
changeset
|
134 cache.w = cc.xPos + cc.ga.w; |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
135 /+if (cc.yPos + cc.ga.h > cache.h) |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
136 cache.h = cc.yPos + cc.ga.h;+/ |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
137 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
138 // Now increment i and continue with the next line if there is one. |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
139 y += lineSep; |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
140 cache.h += lineSep; |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
141 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
142 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
143 |
57
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
144 /** Render a block of text using a cache. Updates the cache if necessary. |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
145 * |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
146 * Params: |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
147 * face = Current typeface pointer; must be passed from font.d (only needed if the cache is |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
148 * invalid) |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
149 * str = Text to render (only needed if the cache is invalid) |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
150 * cache = Cache used to speed up CPU-side rendering code |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
151 * x = Smaller x-coordinate of position |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
152 * y = Smaller y-coordinate of position |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
153 * col = Text colour (note: currently limited to black or white) */ |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
154 void drawCache (FT_Face face, char[] str, ref TextBlock cache, int x, int y, Colour col ) { |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
155 updateCache (face, str, cache); // update if necessary |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
156 debug scope (failure) |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
51
diff
changeset
|
157 logger.error ("drawTextCache failed"); |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
158 |
57
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
159 // opaque (GL_DECAL would be equivalent) |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
160 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
161 |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
162 drawCacheImpl (cache, x, y, col); |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
163 } |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
164 /** A variation of drawCache, for transparent text. |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
165 * |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
166 * Instead of passing the alpha value(s) as arguments, set the openGL colour prior to calling: |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
167 * --- |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
168 * glColor3f (.5f, .5f, .5f); // set alpha to half |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
169 * drawCacheA (face, ...); |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
170 * |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
171 * glColor3ub (0, 255, 127); // alpha 0 for red, 1 for green, half for blue |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
172 * drawCacheA (face, ...); |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
173 * --- |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
174 * |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
175 * The overhead of the transparency is minimal. */ |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
176 void drawCacheA (FT_Face face, char[] str, ref TextBlock cache, int x, int y, Colour col/+ = Colour.WHITE+/) { |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
177 updateCache (face, str, cache); // update if necessary |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
178 debug scope (failure) |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
179 logger.error ("drawTextCache failed"); |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
180 |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
181 // transparency alpha |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
182 // alpha is current colour, per component |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
183 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
184 |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
185 drawCacheImpl (cache, x, y, col); |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
186 } |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
187 |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
188 private void drawCacheImpl (ref TextBlock cache, int x, int y, Colour col) { |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
189 if (DerelictGL.availableVersion() >= GLVersion.Version14) { |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
190 glBlendFunc (GL_CONSTANT_COLOR, GL_ONE_MINUS_SRC_COLOR); |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
191 glBlendColor(col.r, col.g, col.b, 1f); // text colour |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
192 } else |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
193 glBlendFunc (col.nearestGLConst, GL_ONE_MINUS_SRC_COLOR); |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
194 |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
195 glEnable (GL_TEXTURE_2D); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
196 glEnable(GL_BLEND); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
197 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
198 foreach (chr; cache.chars) { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
199 GlyphAttribs* ga = chr.ga; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
200 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
201 glBindTexture(GL_TEXTURE_2D, ga.texID); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
202 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
203 int x1 = x + chr.xPos; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
204 int y1 = y + chr.yPos; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
205 int x2 = x1 + ga.w; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
206 int y2 = y1 + ga.h; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
207 float tx1 = ga.x * wFactor; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
208 float ty1 = ga.y * hFactor; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
209 float tx2 = (ga.x + ga.w) * wFactor; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
210 float ty2 = (ga.y + ga.h) * hFactor; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
211 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
212 glBegin (GL_QUADS); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
213 glTexCoord2f (tx1, ty1); glVertex2i (x1, y1); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
214 glTexCoord2f (tx2, ty1); glVertex2i (x2, y1); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
215 glTexCoord2f (tx2, ty2); glVertex2i (x2, y2); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
216 glTexCoord2f (tx1, ty2); glVertex2i (x1, y2); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
217 glEnd (); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
218 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
219 |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
220 glDisable(GL_TEXTURE_2D); |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
221 glDisable(GL_BLEND); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
222 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
223 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
224 void addGlyph (FT_Face face, dchar chr) { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
225 debug scope (failure) |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
51
diff
changeset
|
226 logger.error ("FontTexture.addGlyph failed!"); |
49
bca7e2342d77
Enabled getting the size of a text block (before or after rendering).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
48
diff
changeset
|
227 |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
228 auto gi = FT_Get_Char_Index (face, chr); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
229 auto g = face.glyph; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
230 |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
49
diff
changeset
|
231 // Use renderMode from options, masking bits which are allowable: |
98
49e7cfed4b34
All types of Option have been converted to use ValueContent classes, and their values can be displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
97
diff
changeset
|
232 if (FT_Load_Glyph (face, gi, FT_LOAD_RENDER | (fontOpts.renderMode() & 0xF0000))) |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
233 throw new fontGlyphException ("Unable to render glyph"); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
234 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
235 auto b = g.bitmap; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
236 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
51
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
237 //glPixelStorei (GL_UNPACK_ROW_LENGTH, b.pitch); |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
238 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
239 GlyphAttribs ga; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
240 ga.w = b.width; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
241 ga.h = b.rows; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
242 ga.left = g.bitmap_left; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
243 ga.top = g.bitmap_top; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
244 ga.advanceX = g.advance.x >> 6; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
245 ga.index = gi; |
51
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
246 if (b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_LCD) |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
247 ga.w /= 3; |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
248 if (b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_LCD_V) |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
249 ga.h /= 3; |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
250 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
251 foreach (ref t; tex) { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
252 if (t.addGlyph (ga)) |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
253 goto gotTexSpace; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
254 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
255 // if here, no existing texture had the room for the glyph so create a new texture |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
256 // NOTE: check if using more than one texture impacts performance due to texture switching |
96
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
94
diff
changeset
|
257 debug logger.trace ("Creating a new font texture."); |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
258 tex ~= TexPacker.create(); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
259 assert (tex[$-1].addGlyph (ga), "Failed to fit glyph in a new texture but addGlyph didn't throw"); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
260 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
261 gotTexSpace: |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
262 glBindTexture(GL_TEXTURE_2D, ga.texID); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
263 GLenum format; |
51
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
264 ubyte[] buffer; // use our own pointer, since for LCD modes we need to perform a conversion |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
265 if (b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_GRAY && b.num_grays == 256) { |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
51
diff
changeset
|
266 assert (b.pitch == b.width, "Have assumed b.pitch == b.width for gray glyphs."); |
51
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
267 buffer = b.buffer[0..b.pitch*b.rows]; |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
268 format = GL_LUMINANCE; |
51
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
269 } else if (b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_LCD) { |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
270 // NOTE: Can't seem to get OpenGL to read freetype's RGB buffers properly, so convent. |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
271 /* NOTE: Sub-pixel rendering probably also needs filtering. I haven't tried, since it's |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
272 * disabled in my build of the library. For a tutorial on the filtering, see: |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
273 * http://dmedia.dprogramming.com/?n=Tutorials.TextRendering1 */ |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
274 buffer = new ubyte[b.width*b.rows]; |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
275 for (uint i = 0; i < b.rows; ++i) |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
276 for (uint j = 0; j < b.width; j+= 3) |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
277 { |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
278 buffer[i*b.width + j + 0] = b.buffer[i*b.pitch + j + 0]; |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
279 buffer[i*b.width + j + 1] = b.buffer[i*b.pitch + j + 1]; |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
280 buffer[i*b.width + j + 2] = b.buffer[i*b.pitch + j + 2]; |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
281 } |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
282 |
98
49e7cfed4b34
All types of Option have been converted to use ValueContent classes, and their values can be displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
97
diff
changeset
|
283 format = (fontOpts.renderMode() & RENDER_LCD_BGR) ? GL_BGR : GL_RGB; |
51
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
284 } else if (b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_LCD_V) { |
83
2813ac68576f
Start of creating a separate gui demo module and leaving mde.d for testing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
285 // NOTE: Notes above apply. But in this case converting the buffers seems essential. |
51
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
286 buffer = new ubyte[b.width*b.rows]; |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
287 for (uint i = 0; i < b.rows; ++i) |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
288 for (uint j = 0; j < b.width; ++j) |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
289 { |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
290 // i/3 is the "real" row, b.width*3 is our width (with subpixels), j is column, |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
291 // i%3 is sub-pixel (R/G/B). i/3*3 necessary to round to multiple of 3 |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
292 buffer[i/3*b.width*3 + 3*j + i%3] = b.buffer[i*b.pitch + j]; |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
293 } |
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
294 |
98
49e7cfed4b34
All types of Option have been converted to use ValueContent classes, and their values can be displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
97
diff
changeset
|
295 format = (fontOpts.renderMode() & RENDER_LCD_BGR) ? GL_BGR : GL_RGB; |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
49
diff
changeset
|
296 } else |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
297 throw new fontGlyphException ("Unsupported freetype bitmap format"); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
298 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
299 glTexSubImage2D(GL_TEXTURE_2D, 0, |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
300 ga.x, ga.y, |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
301 ga.w, ga.h, |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
302 format, GL_UNSIGNED_BYTE, |
51
387a80724c35
Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
50
diff
changeset
|
303 cast(void*) buffer.ptr); |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
304 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
305 cachedGlyphs[chr] = ga; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
306 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
307 |
61
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
57
diff
changeset
|
308 // Draw the first glyph cache texture in the upper-left corner of the screen. |
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
57
diff
changeset
|
309 debug (drawGlyphCache) void drawTexture () { |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
310 if (tex.length == 0) return; |
57
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
311 glEnable (GL_TEXTURE_2D); |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
312 glBindTexture(GL_TEXTURE_2D, tex[0].texID); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
313 glEnable(GL_BLEND); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
314 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_COLOR); |
57
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
315 float[4] Cc = [ 1.0f, 1f, 1f, 1f ]; |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
316 glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, Cc.ptr); |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
317 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
318 glBegin (GL_QUADS); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
319 glTexCoord2f (0f, 0f); glVertex2i (0, 0); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
320 glTexCoord2f (1f, 0f); glVertex2i (dimW, 0); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
321 glTexCoord2f (1f, 1f); glVertex2i (dimW, dimH); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
322 glTexCoord2f (0f, 1f); glVertex2i (0, dimH); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
323 glEnd (); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
324 |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
325 glDisable(GL_TEXTURE_2D); |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
326 glDisable(GL_BLEND); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
327 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
328 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
329 private: |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
330 TexPacker[] tex; // contains the gl texture id and packing data |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
331 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
332 GlyphAttribs[dchar] cachedGlyphs; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
333 int cacheVer = 0; // version of cache, used to make sure TextBlock caches are current. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
334 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
335 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
336 // Use LinePacker for our texture packer: |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
337 alias LinePacker TexPacker; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
338 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
339 /** Represents one gl texture; packs glyphs into lines. */ |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
340 struct LinePacker |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
341 { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
342 // create a new texture |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
343 static LinePacker create () { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
344 LinePacker p; |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
345 //FIXME (gl): why do I get a blank texture when binding to non-0? |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
346 //glGenTextures (1, &(p.texID)); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
347 p.texID = 0; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
348 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
349 // add a pretty background to the texture |
61
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
57
diff
changeset
|
350 debug (drawGlyphCache) { |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
351 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
352 glPixelStorei (GL_UNPACK_ROW_LENGTH, 0); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
353 ubyte[3][dimH][dimW] testTex; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
354 for (size_t i = 0; i < dimW; ++i) |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
355 for (size_t j = 0; j < dimH; ++j) |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
356 { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
357 testTex[i][j][0] = cast(ubyte) (i + j); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
358 testTex[i][j][1] = cast(ubyte) i; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
359 testTex[i][j][2] = cast(ubyte) j; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
360 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
361 void* ptr = testTex.ptr; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
362 } else |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
363 const void* ptr = null; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
364 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
365 // Create a texture without initialising values. |
57
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
366 glBindTexture(GL_TEXTURE_2D, p.texID); |
9e1f05fbbcef
Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
367 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
368 dimW, dimH, 0, |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
369 GL_RGB, GL_UNSIGNED_BYTE, ptr); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
370 return p; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
371 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
372 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
373 /** Find space for a glyph of size attr.w, attr.h within the texture. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
374 * |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
375 * Throws: fontGlyphException if glyph dimensions are larger than the texture. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
376 * |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
377 * Returns false if unable to fit the glyph into the texture, true if successful. If |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
378 * successful, attr's x and y are set to suitible positions such that the rect given by attr's |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
379 * x, y, w & h is a valid subregion of the texture. */ |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
380 bool addGlyph (ref GlyphAttribs attr) { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
381 if (attr.w > dimW || attr.h > dimH) |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
382 throw new fontGlyphException ("Glyph too large to fit texture!"); |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
383 |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
51
diff
changeset
|
384 attr.texID = texID; // Set now. Possibly reset if new texture is needed. |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
51
diff
changeset
|
385 if (attr.w == 0) return true; // 0 sized glyph; x and y are unimportant. |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
51
diff
changeset
|
386 |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
387 bool cantFitExtraLine = nextYPos + attr.h >= dimH; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
388 foreach (ref line; lines) { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
389 if (line.length + attr.w <= dimW && // if sufficient length and |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
390 line.height >= attr.h && // sufficient height and |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
391 (cantFitExtraLine || // either there's not room for another line |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
392 line.height <= attr.h * WASTE_H)) // or we're not wasting much vertical space |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
393 { // then use this line |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
394 attr.x = line.length; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
395 attr.y = line.yPos; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
396 attr.texID = texID; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
397 line.length += attr.w; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
398 return true; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
399 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
400 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
401 // If we didn't return, we didn't use an existing line. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
402 if (cantFitExtraLine) // run out of room |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
403 return false; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
404 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
405 // Still room: add a new line. The new line has the largest yPos (furthest down texture), |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
406 // but the lines array must remain ordered by line height (lowest to heighest). |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
407 Line line; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
408 line.yPos = nextYPos; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
409 line.height = attr.h * EXTRA_H; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
410 line.length = attr.w; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
411 size_t i = 0; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
412 while (i < lines.length && lines[i].height < line.height) ++i; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
413 lines = lines[0..i] ~ line ~ lines[i..$]; // keep lines sorted by height |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
414 nextYPos += line.height; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
415 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
416 attr.x = 0; // first glyph in the line |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
417 attr.y = line.yPos; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
418 return true; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
419 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
420 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
421 // Publically accessible data: |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
422 uint texID; // OpenGL texture identifier (for BindTexture) |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
423 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
424 private: |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
425 const WASTE_H = 1.3; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
426 const EXTRA_H = 1; // can be float/double, just experimenting with 1 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
427 struct Line { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
428 int yPos; // y position (xPos is always 0) |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
429 int height; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
430 int length; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
431 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
432 Line[] lines; |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
433 int nextYPos = 0; // y position for next created line (0 for first line) |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
434 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
435 |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
49
diff
changeset
|
436 // this bit of renderMode, if set, means read glyph as BGR not RGB when using LCD rendering |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
49
diff
changeset
|
437 enum { RENDER_LCD_BGR = 1 << 30 } |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
438 FontOptions fontOpts; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
439 class FontOptions : Options { |
83
2813ac68576f
Start of creating a separate gui demo module and leaving mde.d for testing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
440 /* renderMode have one of the following values, possibly with bit 31 set (see RENDER_LCD_BGR): |
2813ac68576f
Start of creating a separate gui demo module and leaving mde.d for testing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
441 * FT_LOAD_TARGET_NORMAL (0x00000) |
2813ac68576f
Start of creating a separate gui demo module and leaving mde.d for testing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
442 * FT_LOAD_TARGET_LIGHT (0x10000) |
2813ac68576f
Start of creating a separate gui demo module and leaving mde.d for testing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
443 * FT_LOAD_TARGET_LCD (0x30000) |
2813ac68576f
Start of creating a separate gui demo module and leaving mde.d for testing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
444 * FT_LOAD_TARGET_LCD_V (0x40000) |
2813ac68576f
Start of creating a separate gui demo module and leaving mde.d for testing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
445 * The mode FT_LOAD_TARGET_MONO (0x20000) is unsupported. |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
49
diff
changeset
|
446 * |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
49
diff
changeset
|
447 * lcdFilter should come from enum FT_LcdFilter: |
83
2813ac68576f
Start of creating a separate gui demo module and leaving mde.d for testing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
448 * FT_LCD_FILTER_NONE (0), FT_LCD_FILTER_DEFAULT (1), FT_LCD_FILTER_LIGHT (2) */ |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
49
diff
changeset
|
449 mixin (impl!("int renderMode, lcdFilter;")); |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
49
diff
changeset
|
450 |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
49
diff
changeset
|
451 static this() { |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
452 fontOpts = new FontOptions; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
453 Options.addOptionsClass (fontOpts, "FontOptions"); |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
49
diff
changeset
|
454 } |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
49
diff
changeset
|
455 } |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
49
diff
changeset
|
456 |
48
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
457 struct GlyphAttribs { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
458 int x, y; // position within texture |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
459 int w, h; // bitmap size |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
460 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
461 int left, top; // bitmap_left, bitmap_top fields |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
462 int advanceX; // horizontal advance distance |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
463 uint index; // glyph index (within face) |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
464 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
465 uint texID; // gl tex identifier |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
466 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
467 |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
468 /** Cached information for drawing a block of text. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
469 * |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
470 * Struct should be stored externally and updated via references. */ |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
471 struct TextBlock { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
472 CharCache[] chars; // All chars. They hold x & y pos. info, so don't need to know about lines. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
473 int cacheVer = -1; // this is checked on access, and must equal for cache to be valid. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
474 int w, h; /// Size of the block. Likely the only fields of use outside the library. |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
475 } |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
476 struct CharCache { |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
477 GlyphAttribs* ga; // character |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
478 int xPos, yPos; // x,y position |
a98ffb64f066
Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
479 } |