GraphicsText.cpp
上传用户:lhwx1029
上传日期:2013-03-07
资源大小:1173k
文件大小:4k
源码类别:

3D图形编程

开发平台:

Visual C++

  1. /** 3DGPL *************************************************
  2.  * ()                                                     *
  3.  * 2D graphics and 2D clipping.                           *
  4.  *                                                        *
  5.  * Ifdefs:                                                *
  6.  *  _CI_                     Colour/Intensity model;      *
  7.  *  _RGB_                    RGB model.                   *
  8.  *                                                        *
  9.  * Defines:                                               *
  10.  *  G_text                   Rendering a text string.     *
  11.  *                                                        *
  12.  * (c) 1995-98 Sergei Savchenko, (savs@cs.mcgill.ca)      *
  13. **********************************************************/
  14. #include "RayTracing.h"           /* hardware specific stuff */
  15. #include "Colour.h"               /* colour and light */
  16. #include "Graphics.h"           /* graphics functions */
  17. extern HW_pixel *G_c_buffer;                /* the bitmap's bits */
  18. extern int G_page_start;                    /* always 0 for _MONO_ */
  19. unsigned char G_font[354]=                  /* The 8x6 font */
  20. {
  21.  0x00,0x00,0x00,0x00,0x00,0x00, 0x30,0x30,0x30,0x00,0x30,0x00,
  22.  0xd8,0x90,0x00,0x00,0x00,0x00, 0x6c,0xfe,0x6c,0xfe,0x6c,0x00,
  23.  0x7e,0xd0,0x7c,0x16,0xfc,0x00, 0xcc,0x18,0x30,0x60,0xcc,0x00,
  24.  0x60,0x90,0x74,0xd8,0x6c,0x00, 0x30,0x20,0x00,0x00,0x00,0x00,
  25.  0x60,0xc0,0xc0,0xc0,0x60,0x00, 0x18,0x0c,0x0c,0x0c,0x18,0x00,
  26.  0x6c,0x38,0xfe,0x38,0x6c,0x00, 0x00,0x30,0xfc,0x30,0x00,0x00,
  27.  0x00,0x00,0x00,0x30,0x20,0x00, 0x00,0x00,0x7c,0x00,0x00,0x00,
  28.  0x00,0x00,0x00,0x00,0xc0,0x00, 0x0c,0x18,0x30,0x60,0xc0,0x00,
  29.  0x78,0x84,0x84,0x84,0x78,0x00, 0x04,0x0c,0x14,0x04,0x04,0x00,
  30.  0x78,0x84,0x18,0x20,0x7c,0x00, 0x78,0x04,0x38,0x04,0x78,0x00,
  31.  0x84,0x84,0xfc,0x04,0x04,0x00, 0xfc,0x80,0xf8,0x04,0xf8,0x00,
  32.  0x30,0x40,0xf8,0x84,0x78,0x00, 0xfc,0x04,0x08,0x10,0x10,0x00,
  33.  0x78,0x84,0x78,0x84,0x78,0x00, 0x78,0x84,0x7c,0x08,0x30,0x00,
  34.  0x00,0x30,0x00,0x30,0x00,0x00, 0x00,0x30,0x00,0x30,0x20,0x00,
  35.  0x30,0x60,0xc0,0x60,0x30,0x00, 0x00,0x7c,0x00,0x7c,0x00,0x00,
  36.  0x30,0x18,0x0c,0x18,0x30,0x00, 0x78,0xcc,0x18,0x00,0x18,0x00,
  37.  0x78,0xcc,0xdc,0xc0,0x7c,0x00, 0x30,0x48,0x84,0xfc,0x84,0x00,
  38.  0xf8,0x84,0xf8,0x84,0xf8,0x00, 0x7c,0x80,0x80,0x80,0x7c,0x00,
  39.  0xf8,0x84,0x84,0x84,0xf8,0x00, 0xfc,0x80,0xf0,0x80,0xfc,0x00,
  40.  0xfc,0x80,0xf0,0x80,0x80,0x00, 0x7c,0x80,0x84,0x84,0x7c,0x00,
  41.  0x84,0x84,0xfc,0x84,0x84,0x00, 0x10,0x10,0x10,0x10,0x10,0x00,
  42.  0x04,0x04,0x04,0x84,0x78,0x00, 0x84,0x88,0xf0,0x88,0x84,0x00,
  43.  0x80,0x80,0x80,0x80,0xfc,0x00, 0x82,0xc6,0xaa,0x92,0x82,0x00,
  44.  0x84,0xc4,0xa4,0x94,0x8c,0x00, 0x78,0x84,0x84,0x84,0x78,0x00,
  45.  0xf8,0x84,0xf8,0x80,0x80,0x00, 0x78,0x84,0x84,0x78,0x1c,0x00,
  46.  0xf8,0x84,0xf8,0x90,0x88,0x00, 0x7c,0x80,0x78,0x04,0xf8,0x00,
  47.  0xfe,0x10,0x10,0x10,0x10,0x00, 0x84,0x84,0x84,0x84,0x78,0x00,
  48.  0x84,0x84,0x84,0x48,0x30,0x00, 0x82,0x82,0x92,0xaa,0x44,0x00,
  49.  0x84,0x48,0x30,0x48,0x84,0x00, 0x88,0x88,0x50,0x20,0x20,0x00,
  50.  0xf8,0x10,0x20,0x40,0xf8,0x00
  51. };
  52. /**********************************************************
  53.  * Rendering a text string, no clipping is performed !    *
  54. **********************************************************/
  55. #if defined(_CI_)
  56. void G_text(int x,int y,char *txt,
  57.             HW_pixel colour,int intensity
  58.    )
  59. #endif
  60. #if defined(_RGB_)
  61. void G_text(int x,int y,char *txt,
  62.             HW_pixel colour,int red,int green,int blue
  63.            )
  64. #endif
  65. {
  66.  int nm,i,j;
  67.  unsigned char cur;
  68.  HW_pixel *adr,*l_adr;
  69. #if defined(_CI_)
  70.  register HW_pixel hwcolour=CL_light(colour,intensity);
  71. #endif
  72. #if defined(_RGB_)
  73.  register HW_pixel hwcolour=CL_light(colour,red,green,blue);
  74. #endif
  75.  adr=G_c_buffer+G_page_start+HW_SCREEN_LINE_SIZE*y+x;
  76.  while(*txt!='')                          /* until the end of the string */
  77.  {
  78.   nm=((*txt++)-' ');                        /* starting from space */
  79.   if(nm>58) nm-=' ';                        /* to uppercase 58='Z'-' ' */
  80.   nm*=6;                                    /* 6 bytes per char */
  81.   for(i=0,l_adr=adr;i<6;i++,l_adr+=HW_SCREEN_LINE_SIZE)
  82.   {
  83.    cur=G_font[nm++];
  84.    for(j=0;j<8;j++)
  85.     if(cur&(0x80>>j)) *(l_adr+j)=hwcolour;
  86.   }
  87.   adr+=8;                                   /* next word */
  88.  }
  89. }
  90. /**********************************************************/