1 /*===========================================================================*/
3 /* Mesa-3.0 DirectX 6 Driver */
7 /* http://www.altsoftware.com/ */
9 /* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */
10 /*===========================================================================*/
13 /*=============================================================================
36 =============================================================================*/
62 #define BIT1 0x00000001
63 #define BIT2 0x00000002
64 #define BIT3 0x00000004
65 #define BIT4 0x00000008
66 #define BIT5 0x00000010
67 #define BIT6 0x00000020
68 #define BIT7 0x00000040
75 #define LEFT (TLEFT|BLEFT)
78 #define RIGHT (TRIGHT|BRIGHT)
79 #define ALL 0xFFFFFFFF
81 /*===========================================================================*/
82 /* This is the static array that will map the ASCII value of the character */
83 /* being draw to the bit mask that will be scan converted to the LED display.*/
84 /*===========================================================================*/
85 DWORD textBitMasks[] =
119 0x00000000, // 032 'SPC'
135 (ALL &~ MIDDLE), // 048 '0'
137 (ALL &~ TLEFT &~ BRIGHT), // 050 '2'
138 (ALL &~ LEFT), // 051 '3'
139 (TLEFT | MIDDLE | RIGHT), // 052 '4'
140 (ALL &~ TRIGHT &~ BLEFT), // 053 '5'
141 (ALL &~ TRIGHT), // 054 '6'
142 (TOP | RIGHT), // 055 '7'
144 (ALL &~ BOTTOM &~ BLEFT), // 057 '9'
152 (ALL &~ BOTTOM), // 065 'A'
154 (TOP | LEFT | BOTTOM), // 067 'C'
155 (ALL &~ MIDDLE), // 068 'D'
156 (ALL &~ RIGHT), // 069 'E'
157 (LEFT | TOP | MIDDLE), // 070 'F'
158 0x00000000, // 071 'G'
159 (ALL &~ TOP &~ BOTTOM), // 072 'H'
161 (RIGHT | BOTTOM), // 074 'J'
162 0x00000000, // 075 'K'
163 (LEFT | BOTTOM), // 076 'L'
164 0x00000000, // 088 'M'
165 0x00000000, // 089 'N'
166 (ALL &~ MIDDLE), // 090 'O'
167 (ALL &~ BRIGHT &~ BOTTOM),// 091 'P'
168 0x00000000, // 092 'Q'
169 0x00000000, // 093 'R'
170 (ALL &~ TRIGHT &~ BLEFT), // 094 'S'
171 0X00000000, // 095 'T'
172 (LEFT | RIGHT | BOTTOM), // 096 'U'
173 0x00000000, // 097 'V'
174 0x00000000, // 098 'W'
175 0x00000000, // 099 'X'
176 0x00000000, // 1000 'Z'
177 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, // 100
178 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, // 104
179 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, // 108
180 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, // 112
181 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, // 116
182 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, // 120
183 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF // 124
189 #define CM ((CY-(CT*3.0f))/2.0f)
201 { (CX-CT), (CY-CT) },
203 /* Middle outsides. */
204 { 0.0f, (CT+CM+CT) },
212 { (CX-CT), (CT+CM+CT) },
213 { (CX-CT), (CT+CM) },
221 /* Bottom outsides. */
226 static int ConvertCharacter( char *c, int cIndex, PD3DFONTMETRICS pfntMetrics );
228 D3DTLVERTEX TextVertices[MAX_VERTICES];
229 /*===========================================================================*/
230 /* When we attach I will zero out the whole D3D vertex buffer I'm using for */
231 /* the text. This way I don't need to set all the redundant values. I also */
232 /* set all the oow values to 1 as I will be doing direct rendering. */
233 /*===========================================================================*/
234 /* RETURN: TRUE, FALSE. */
235 /*===========================================================================*/
236 extern "C" BOOL InitD3DText( void )
240 /* Set the D3D Vertex Buffer up once so we don't do redundant changes. */
241 memset( &TextVertices[0], 0, sizeof(TextVertices) );
242 for( index = 0; index < MAX_VERTICES; index++ )
243 TextVertices[index].rhw = D3DVAL( 1.0 );
247 /*===========================================================================*/
248 /* This function takes a single character and draw it using the supplied */
249 /* fontmetrics structure. */
250 /*===========================================================================*/
252 /*===========================================================================*/
253 extern "C" void d3dTextDrawString( char *pszString, int x, int y, PD3DFONTMETRICS pfntMetrics )
261 /* Find the max width/height of a character and add the spacing so */
262 /* that we can use this value to calculate the x,y of the character.*/
263 cWidth = (cWidth * pfntMetrics->fntXScale) + pfntMetrics->fntXSpacing;
264 cHeight = (cHeight * pfntMetrics->fntYScale) + pfntMetrics->fntYSpacing;
266 /* Walk the string. This must be NULL terminated. */
267 for( cIndex = 0, nIndex = 0; *pszString; pszString++, cIndex = nIndex, x++ )
269 /* Convert the character and get the index into the text vertex buffer. */
270 nIndex = ConvertCharacter( &pszString[0], cIndex, pfntMetrics );
271 if ( (nIndex - cIndex) > 2 )
273 /* Modify the text vertex buffer based on the fntMetrics structure. */
274 for( index = cIndex; index < nIndex; index++ )
276 /* Scale the character. */
277 TextVertices[index].sx *= pfntMetrics->fntXScale;
278 TextVertices[index].sy *= pfntMetrics->fntYScale;
280 /* Move the character. */
281 TextVertices[index].sx += (cWidth*x);
282 TextVertices[index].sy += (cHeight*y);
285 TextVertices[index].color = pfntMetrics->dwColor;
293 /* Set the states that slim things down. */
294 pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_CULLMODE, D3DCULL_NONE );
295 pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID );
296 pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ZENABLE, FALSE );
297 pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ZWRITEENABLE , FALSE );
298 pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ALPHATESTENABLE, FALSE );
299 pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, FALSE );
301 /* Blast them baby... */
302 pfntMetrics->lpD3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST,
304 (LPVOID)&TextVertices[0],
306 (D3DDP_DONOTCLIP | D3DDP_DONOTLIGHT) );
308 /*===========================================================================*/
309 /* This function takes a single character and draw it directly to the screen*/
310 /* unsing the supplied fntMetrics structure. The character will be drawn at */
311 /* the supplied x,y. The x,y position is relative to the top left and uses */
312 /* the spacing in the fntMetrics structure. */
313 /*===========================================================================*/
315 /*===========================================================================*/
316 extern "C" void d3dTextDrawCharacter( char *c, int x, int y, PD3DFONTMETRICS pfntMetrics )
323 /* Convert the character and get the index into the text vertex buffer. */
324 cIndex = ConvertCharacter( c, 0, pfntMetrics );
328 /* Find the max width/height of a character and add the spacing so */
329 /* that we can use this value to calculate the x,y of the character.*/
330 cWidth = (cWidth * pfntMetrics->fntXScale) + pfntMetrics->fntXSpacing;
331 cHeight = (cHeight * pfntMetrics->fntYScale) + pfntMetrics->fntYSpacing;
333 /* Modify the text vertex buffer based on the fntMetrics structure. */
334 for( index = 0; index < cIndex; index++ )
336 /* Scale the character. */
337 TextVertices[index].sx *= pfntMetrics->fntXScale;
338 TextVertices[index].sy *= pfntMetrics->fntYScale;
340 /* Move the character. */
341 TextVertices[index].sx += (cWidth*x);
342 TextVertices[index].sy += (cHeight*y);
345 TextVertices[index].color = pfntMetrics->dwColor;
349 /* Set the states that slim things down. */
350 pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_CULLMODE, D3DCULL_NONE );
351 pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID );
352 pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ZENABLE, FALSE );
353 pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ZWRITEENABLE , FALSE );
354 pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ALPHATESTENABLE, FALSE );
355 pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, FALSE );
357 /* Blast them baby... */
358 pfntMetrics->lpD3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST,
360 (LPVOID)&TextVertices[0],
362 (D3DDP_DONOTCLIP | D3DDP_DONOTLIGHT) );
364 /*===========================================================================*/
365 /* This function takes a single character and draw it using the supplied */
366 /* fontmetrics structure. */
367 /*===========================================================================*/
369 /*===========================================================================*/
370 static int ConvertCharacter( char *c, int cIndex, PD3DFONTMETRICS pfntMetrics )
372 DWORD asciiChar = (int)(*c);
374 /* Handle the TOP line. */
375 if ( textBitMasks[asciiChar] & BIT1 )
377 TextVertices[cIndex].sx = D3DVAL( lCoords[TL_0][0] );
378 TextVertices[cIndex++].sy= D3DVAL( lCoords[TL_0][1] );
379 TextVertices[cIndex].sx = D3DVAL( lCoords[TR_0][0] );
380 TextVertices[cIndex++].sy= D3DVAL( lCoords[TR_0][1] );
381 TextVertices[cIndex].sx = D3DVAL( lCoords[TR_1][0] );
382 TextVertices[cIndex++].sy= D3DVAL( lCoords[TR_1][1] );
383 TextVertices[cIndex].sx = D3DVAL( lCoords[TR_1][0] );
384 TextVertices[cIndex++].sy= D3DVAL( lCoords[TR_1][1] );
385 TextVertices[cIndex].sx = D3DVAL( lCoords[TL_1][0] );
386 TextVertices[cIndex++].sy= D3DVAL( lCoords[TL_1][1] );
387 TextVertices[cIndex].sx = D3DVAL( lCoords[TL_0][0] );
388 TextVertices[cIndex++].sy= D3DVAL( lCoords[TL_0][1] );
391 /* Handle the TOP/BOTTOM RIGHT lines. */
392 // if ( textBitMasks[index] & (BIT2|BIT3) )
395 TextVertices[cIndex].sx = D3DVAL( lCoords[TR_1][0] );
396 TextVertices[cIndex++].sy= D3DVAL( lCoords[TR_1][1] );
397 TextVertices[cIndex].sx = D3DVAL( lCoords[TRR][0] );
398 TextVertices[cIndex++].sy= D3DVAL( lCoords[TRR][1] );
399 TextVertices[cIndex].sx = D3DVAL( lCoords[BRR][0] );
400 TextVertices[cIndex++].sy= D3DVAL( lCoords[BRR][1] );
401 TextVertices[cIndex].sx = D3DVAL( lCoords[BRR][0] );
402 TextVertices[cIndex++].sy= D3DVAL( lCoords[BRR][1] );
403 TextVertices[cIndex].sx = D3DVAL( lCoords[BR_0][0] );
404 TextVertices[cIndex++].sy= D3DVAL( lCoords[BR_0][1] );
405 TextVertices[cIndex].sx = D3DVAL( lCoords[TR_1][0] );
406 TextVertices[cIndex++].sy= D3DVAL( lCoords[TR_1][1] );
410 if ( textBitMasks[asciiChar] & BIT2 )
412 TextVertices[cIndex].sx = D3DVAL( lCoords[TR_1][0] );
413 TextVertices[cIndex++].sy = D3DVAL( lCoords[TR_1][1] );
414 TextVertices[cIndex].sx = D3DVAL( lCoords[TRR][0] );
415 TextVertices[cIndex++].sy = D3DVAL( lCoords[TRR][1] );
416 TextVertices[cIndex].sx = D3DVAL( lCoords[MRR_0][0] );
417 TextVertices[cIndex++].sy = D3DVAL( lCoords[MRR_0][1] );
418 TextVertices[cIndex].sx = D3DVAL( lCoords[MRR_0][0] );
419 TextVertices[cIndex++].sy = D3DVAL( lCoords[MRR_0][1] );
420 TextVertices[cIndex].sx = D3DVAL( lCoords[MR_0][0] );
421 TextVertices[cIndex++].sy = D3DVAL( lCoords[MR_0][1] );
422 TextVertices[cIndex].sx = D3DVAL( lCoords[TR_1][0] );
423 TextVertices[cIndex++].sy = D3DVAL( lCoords[TR_1][1] );
425 if ( textBitMasks[asciiChar] & BIT3 )
427 TextVertices[cIndex].sx = D3DVAL( lCoords[MR_1][0] );
428 TextVertices[cIndex++].sy = D3DVAL( lCoords[MR_1][1] );
429 TextVertices[cIndex].sx = D3DVAL( lCoords[MRR_1][0] );
430 TextVertices[cIndex++].sy = D3DVAL( lCoords[MRR_1][1] );
431 TextVertices[cIndex].sx = D3DVAL( lCoords[BRR][0] );
432 TextVertices[cIndex++].sy = D3DVAL( lCoords[BRR][1] );
433 TextVertices[cIndex].sx = D3DVAL( lCoords[BRR][0] );
434 TextVertices[cIndex++].sy = D3DVAL( lCoords[BRR][1] );
435 TextVertices[cIndex].sx = D3DVAL( lCoords[BR_0][0] );
436 TextVertices[cIndex++].sy = D3DVAL( lCoords[BR_0][1] );
437 TextVertices[cIndex].sx = D3DVAL( lCoords[MR_1][0] );
438 TextVertices[cIndex++].sy = D3DVAL( lCoords[MR_1][1] );
442 /* Handle the TOP/BOTTOM LEFT lines. */
443 // if ( textBitMasks[asciiChar] & (BIT5|BIT6) )
446 TextVertices[cIndex].sx = D3DVAL( lCoords[TLL][0] );
447 TextVertices[cIndex++].sy= D3DVAL( lCoords[TLL][1] );
448 TextVertices[cIndex].sx = D3DVAL( lCoords[TL_1][0] );
449 TextVertices[cIndex++].sy= D3DVAL( lCoords[TL_1][1] );
450 TextVertices[cIndex].sx = D3DVAL( lCoords[BL_0][0] );
451 TextVertices[cIndex++].sy= D3DVAL( lCoords[BL_0][1] );
452 TextVertices[cIndex].sx = D3DVAL( lCoords[BL_0][0] );
453 TextVertices[cIndex++].sy= D3DVAL( lCoords[BL_0][1] );
454 TextVertices[cIndex].sx = D3DVAL( lCoords[BLL][0] );
455 TextVertices[cIndex++].sy= D3DVAL( lCoords[BLL][1] );
456 TextVertices[cIndex].sx = D3DVAL( lCoords[TLL][0] );
457 TextVertices[cIndex++].sy= D3DVAL( lCoords[TLL][1] );
461 if ( textBitMasks[asciiChar] & BIT5 )
463 TextVertices[cIndex].sx = D3DVAL( lCoords[MLL_1][0] );
464 TextVertices[cIndex++].sy = D3DVAL( lCoords[MLL_1][1] );
465 TextVertices[cIndex].sx = D3DVAL( lCoords[ML_1][0] );
466 TextVertices[cIndex++].sy = D3DVAL( lCoords[ML_1][1] );
467 TextVertices[cIndex].sx = D3DVAL( lCoords[BL_0][0] );
468 TextVertices[cIndex++].sy = D3DVAL( lCoords[BL_0][1] );
469 TextVertices[cIndex].sx = D3DVAL( lCoords[BL_0][0] );
470 TextVertices[cIndex++].sy = D3DVAL( lCoords[BL_0][1] );
471 TextVertices[cIndex].sx = D3DVAL( lCoords[BLL][0] );
472 TextVertices[cIndex++].sy = D3DVAL( lCoords[BLL][1] );
473 TextVertices[cIndex].sx = D3DVAL( lCoords[MLL_1][0] );
474 TextVertices[cIndex++].sy = D3DVAL( lCoords[MLL_1][1] );
476 if ( textBitMasks[asciiChar] & BIT6 )
478 TextVertices[cIndex].sx = D3DVAL( lCoords[TLL][0] );
479 TextVertices[cIndex++].sy = D3DVAL( lCoords[TLL][1] );
480 TextVertices[cIndex].sx = D3DVAL( lCoords[TL_1][0] );
481 TextVertices[cIndex++].sy = D3DVAL( lCoords[TL_1][1] );
482 TextVertices[cIndex].sx = D3DVAL( lCoords[ML_0][0] );
483 TextVertices[cIndex++].sy = D3DVAL( lCoords[ML_0][1] );
484 TextVertices[cIndex].sx = D3DVAL( lCoords[ML_0][0] );
485 TextVertices[cIndex++].sy = D3DVAL( lCoords[ML_0][1] );
486 TextVertices[cIndex].sx = D3DVAL( lCoords[MLL_0][0] );
487 TextVertices[cIndex++].sy = D3DVAL( lCoords[MLL_0][1] );
488 TextVertices[cIndex].sx = D3DVAL( lCoords[TLL][0] );
489 TextVertices[cIndex++].sy = D3DVAL( lCoords[TLL][1] );
493 /* Handle the MIDDLE line. */
494 if ( textBitMasks[asciiChar] & BIT7 )
496 TextVertices[cIndex].sx = D3DVAL( lCoords[ML_0][0] );
497 TextVertices[cIndex++].sy= D3DVAL( lCoords[ML_0][1] );
498 TextVertices[cIndex].sx = D3DVAL( lCoords[MR_0][0] );
499 TextVertices[cIndex++].sy= D3DVAL( lCoords[MR_0][1] );
500 TextVertices[cIndex].sx = D3DVAL( lCoords[MR_1][0] );
501 TextVertices[cIndex++].sy= D3DVAL( lCoords[MR_1][1] );
502 TextVertices[cIndex].sx = D3DVAL( lCoords[MR_1][0] );
503 TextVertices[cIndex++].sy= D3DVAL( lCoords[MR_1][1] );
504 TextVertices[cIndex].sx = D3DVAL( lCoords[ML_1][0] );
505 TextVertices[cIndex++].sy= D3DVAL( lCoords[ML_1][1] );
506 TextVertices[cIndex].sx = D3DVAL( lCoords[ML_0][0] );
507 TextVertices[cIndex++].sy= D3DVAL( lCoords[ML_0][1] );
510 /* Handle the BOTTOM line. */
511 if ( textBitMasks[asciiChar] & BIT4 )
513 TextVertices[cIndex].sx = D3DVAL( lCoords[BL_0][0] );
514 TextVertices[cIndex++].sy= D3DVAL( lCoords[BL_0][1] );
515 TextVertices[cIndex].sx = D3DVAL( lCoords[BR_0][0] );
516 TextVertices[cIndex++].sy= D3DVAL( lCoords[BR_0][1] );
517 TextVertices[cIndex].sx = D3DVAL( lCoords[BR_1][0] );
518 TextVertices[cIndex++].sy= D3DVAL( lCoords[BR_1][1] );
519 TextVertices[cIndex].sx = D3DVAL( lCoords[BR_1][0] );
520 TextVertices[cIndex++].sy= D3DVAL( lCoords[BR_1][1] );
521 TextVertices[cIndex].sx = D3DVAL( lCoords[BL_1][0] );
522 TextVertices[cIndex++].sy= D3DVAL( lCoords[BL_1][1] );
523 TextVertices[cIndex].sx = D3DVAL( lCoords[BL_0][0] );
524 TextVertices[cIndex++].sy= D3DVAL( lCoords[BL_0][1] );