Changeset 57:9e1f05fbbcef
- Timestamp:
- 06/14/08 08:09:03 (7 months ago)
- Files:
-
- codeDoc/jobs.txt (modified) (1 diff)
- codeDoc/mergetag/file-format-binary.txt (modified) (1 diff)
- data/conf/fonts.mtt (modified) (1 diff)
- data/conf/gui.mtt (modified) (1 diff)
- mde/gl/basic.d (modified) (2 diffs)
- mde/gui/widget/miscWidgets.d (modified) (3 diffs)
- mde/resource/FontTexture.d (modified) (5 diffs)
- mde/resource/font.d (modified) (6 diffs)
- mde/types/basic.d (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
codeDoc/jobs.txt
r56 r57 52 52 53 53 54 Done (for gitlog message):55 Implemented gl.texture module to load textures from file (untested).56 Fixed log level/option setting in Init.54 Done (for mercurial log message): 55 Coloured and alpha-blended text is now supported. 56 TextWidgets get text colour from argument. codeDoc/mergetag/file-format-binary.txt
r26 r57 1 1 Copyright © 2007-2008 Diggory Hardy 2 2 License: GNU General Public License version 2 or later (see COPYING) 3 4 5 No file format is set yet; this basically includes possibilities. The file format may or may not be compatible across platforms; if not it may just be used as a cache (i.e. open .mtt/.mtb, whichever is newest, and if it's .mtt then save a .mtb version). 3 6 4 7 data/conf/fonts.mtt
r48 r57 1 1 {MT01} 2 2 <char[]|fallback="default"> 3 !{Lists available fonts. This data may be moved to options for more generic handling.} 3 4 {default} 4 5 <char[]|path="/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf"> data/conf/gui.mtt
r47 r57 8 8 <int|x=150> 9 9 <int|y=200> 10 <int[][int]|widgetData=[0:[0xB004,5,5,2,1,2,1,2,1,1,1,1,1,2,1,2,1,2,1,1,1,1,1,2,1,2,1,2],1:[0x3001],2:[0x2 ]]>10 <int[][int]|widgetData=[0:[0xB004,5,5,2,1,2,1,2,1,1,1,1,1,2,1,2,1,2,1,1,1,1,1,2,1,2,1,2],1:[0x3001],2:[0x2,0xFFFF00]]> 11 11 {WEmbedded} 12 12 <int|x=20> mde/gl/basic.d
r48 r57 25 25 //BEGIN GL & window setup 26 26 void glSetup () { 27 glDisable(GL_LIGHTING); 27 28 glDisable(GL_DEPTH_TEST); 28 29 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); … … 30 31 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 31 32 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 32 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);33 33 glEnable(GL_TEXTURE_2D); 34 glShadeModel(GL_ FLAT);34 glShadeModel(GL_SMOOTH); 35 35 36 36 glClearColor (0.0f, 0.0f, 0.0f, 0.0f); mde/gui/widget/miscWidgets.d
r49 r57 107 107 { 108 108 this (IWindow wind, int[] data) { 109 if (data.length != 1) throw new WidgetDataException;109 if (data.length != 2) throw new WidgetDataException; 110 110 if (font is null) font = FontStyle.get("default"); 111 111 font.updateBlock (str, textCache); 112 112 mw = textCache.w; 113 113 mh = textCache.h; 114 colour = Colour (cast(ubyte) (data[1] >> 16u), 115 cast(ubyte) (data[1] >> 8u), 116 cast(ubyte) data[1] ); 114 117 super (wind,data); 115 118 } … … 117 120 void draw () { 118 121 super.draw(); 119 font.textBlock (x,y, str, textCache ); // test new-lines and unicode characters122 font.textBlock (x,y, str, textCache, colour); // test new-lines and unicode characters 120 123 } 121 124 … … 123 126 const str = "Text Widget\nαβγ â ÎÎÎ"; 124 127 TextBlock textCache; 128 Colour colour; 125 129 static FontStyle font; 126 130 } mde/resource/FontTexture.d
r53 r57 25 25 module mde.resource.FontTexture; 26 26 27 import mde.types.basic; // Colour 27 28 import mde.Options; 28 29 import mde.resource.exception; … … 161 162 } 162 163 163 /** Render a block of text using a cache. Updates the cache if necessary. */ 164 void drawTextCache (FT_Face face, char[] str, ref TextBlock cache, int x, int y) { 164 /** Render a block of text using a cache. Updates the cache if necessary. 165 * 166 * Params: 167 * face = Current typeface pointer; must be passed from font.d (only needed if the cache is 168 * invalid) 169 * str = Text to render (only needed if the cache is invalid) 170 * cache = Cache used to speed up CPU-side rendering code 171 * x = Smaller x-coordinate of position 172 * y = Smaller y-coordinate of position 173 * col = Text colour (note: currently limited to black or white) */ 174 void drawCache (FT_Face face, char[] str, ref TextBlock cache, int x, int y, Colour col ) { 165 175 updateCache (face, str, cache); // update if necessary 166 176 debug scope (failure) 167 177 logger.error ("drawTextCache failed"); 168 178 179 // opaque (GL_DECAL would be equivalent) 180 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 181 182 drawCacheImpl (cache, x, y, col); 183 } 184 /** A variation of drawCache, for transparent text. 185 * 186 * Instead of passing the alpha value(s) as arguments, set the openGL colour prior to calling: 187 * --- 188 * glColor3f (.5f, .5f, .5f); // set alpha to half 189 * drawCacheA (face, ...); 190 * 191 * glColor3ub (0, 255, 127); // alpha 0 for red, 1 for green, half for blue 192 * drawCacheA (face, ...); 193 * --- 194 * 195 * The overhead of the transparency is minimal. */ 196 void drawCacheA (FT_Face face, char[] str, ref TextBlock cache, int x, int y, Colour col/+ = Colour.WHITE+/) { 197 updateCache (face, str, cache); // update if necessary 198 debug scope (failure) 199 logger.error ("drawTextCache failed"); 200 201 // transparency alpha 202 // alpha is current colour, per component 203 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 204 205 drawCacheImpl (cache, x, y, col); 206 } 207 208 private void drawCacheImpl (ref TextBlock cache, int x, int y, Colour col) { 209 if (DerelictGL.availableVersion() >= GLVersion.Version14) { 210 glBlendFunc (GL_CONSTANT_COLOR, GL_ONE_MINUS_SRC_COLOR); 211 glBlendColor(col.r, col.g, col.b, 1f); // text colour 212 } else 213 glBlendFunc (col.nearestGLConst, GL_ONE_MINUS_SRC_COLOR); 214 169 215 glEnable (GL_TEXTURE_2D); 170 216 glEnable(GL_BLEND); 171 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_COLOR);172 217 173 218 foreach (chr; cache.chars) { … … 282 327 void drawTexture () { // temp func 283 328 if (tex.length == 0) return; 329 glEnable (GL_TEXTURE_2D); 284 330 glBindTexture(GL_TEXTURE_2D, tex[0].texID); 285 glEnable (GL_TEXTURE_2D);286 331 glEnable(GL_BLEND); 287 332 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_COLOR); 333 float[4] Cc = [ 1.0f, 1f, 1f, 1f ]; 334 glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, Cc.ptr); 335 glColor3f (1f, 0f, 0f); 288 336 289 337 glBegin (GL_QUADS); … … 313 361 static LinePacker create () { 314 362 LinePacker p; 315 //FIXME: check for error?363 //FIXME: why do I get a blank texture when binding to non-0? 316 364 //glGenTextures (1, &(p.texID)); 317 365 p.texID = 0; 318 //FIXME: why do I get a blank texture when using bind?319 glBindTexture(GL_TEXTURE_2D, p.texID);320 366 321 367 // add a pretty background to the texture 322 static if ( false) {368 static if (true) { 323 369 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 324 370 glPixelStorei (GL_UNPACK_ROW_LENGTH, 0); … … 336 382 337 383 // Create a texture without initialising values. 338 glTexImage2D(GL_TEXTURE_2D, 0, 3, 384 glBindTexture(GL_TEXTURE_2D, p.texID); 385 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 339 386 dimW, dimH, 0, 340 387 GL_RGB, GL_UNSIGNED_BYTE, ptr); mde/resource/font.d
r53 r57 17 17 module mde.resource.font; 18 18 19 public import mde.types.basic; // Colour 19 20 import mde.Options; 20 21 import mde.resource.FontTexture; … … 229 230 * The text block is drawn with top-left corner at x,y. To put the text's baseline at a given 230 231 * y coordinate would require some changes. Line height is currently variable, depending on the 231 * highest glyph in the line. 232 * highest glyph in the line (should probably be fixed: FIXME). 233 * 234 * Specify the text's colour with col; currently this is only Colour.WHITE or Colour.BLACK 235 * (FIXME). FIXME: add alpha support. 232 236 * 233 237 * As a CPU-side code optimisation, store a TextBlock (unique to str) and pass a reference as … … 247 251 * of a text block is to use a TextBlock cache and update it, either with this function or with 248 252 * the updateBlock function. */ 249 void textBlock (int x, int y, char[] str, ref TextBlock cache ) {253 void textBlock (int x, int y, char[] str, ref TextBlock cache, Colour col) { 250 254 try { 251 fontTex.draw TextCache (face, str, cache, x, y);255 fontTex.drawCache (face, str, cache, x, y, col); 252 256 } catch (Exception e) { 253 257 logger.warn ("Exception while drawing text: "~e.msg); … … 255 259 } 256 260 /** ditto */ 257 void textBlock (int x, int y, char[] str ) {261 void textBlock (int x, int y, char[] str, Colour col) { 258 262 try { 259 263 // Using the cache method for one-time use is slightly less than optimal, but doing so … … 261 265 // would be horrible). 262 266 TextBlock cache; 263 fontTex.draw TextCache (face, str, cache, x, y);267 fontTex.drawCache (face, str, cache, x, y, col); 264 268 } catch (Exception e) { 265 269 logger.warn ("Exception while drawing text: "~e.msg); … … 267 271 } 268 272 273 /** A variation of textBlock for transparency. 274 * 275 * Set the alpha by calling glColor*() first. See FontTexture.drawCacheA()'s documentation for 276 * details. */ 277 void textBlockA (int x, int y, char[] str, ref TextBlock cache, Colour col) { 278 try { 279 fontTex.drawCacheA (face, str, cache, x, y, col); 280 } catch (Exception e) { 281 logger.warn ("Exception while drawing text: "~e.msg); 282 } 283 } 269 284 270 285 /** The font-specified vertical distance between the baseline of consecutive lines. */
