home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / quakeworld_src / client / gl_ngraph.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-17  |  3.3 KB  |  142 lines

  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  12.  
  13. See the GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. */
  20. // gl_ngraph.c
  21.  
  22. #include "quakedef.h"
  23.  
  24. extern byte   *draw_chars;        // 8*8 graphic characters
  25.  
  26. int netgraphtexture;  // netgraph texture
  27.  
  28. #define NET_GRAPHHEIGHT 32
  29.  
  30. static  byte ngraph_texels[NET_GRAPHHEIGHT][NET_TIMINGS];
  31.  
  32. static void R_LineGraph (int x, int h)
  33. {
  34.   int   i;
  35.   int   s;
  36.   int   color;
  37.  
  38.   s = NET_GRAPHHEIGHT;
  39.  
  40.   if (h == 10000)
  41.     color = 0x6f; // yellow
  42.   else if (h == 9999)
  43.     color = 0x4f; // red
  44.   else if (h == 9998)
  45.     color = 0xd0; // blue
  46.   else
  47.     color = 0xfe; // white
  48.  
  49.   if (h>s)
  50.     h = s;
  51.   
  52.   for (i=0 ; i<h ; i++)
  53.     if (i & 1)
  54.       ngraph_texels[NET_GRAPHHEIGHT - i - 1][x] = 0xff;
  55.     else
  56.       ngraph_texels[NET_GRAPHHEIGHT - i - 1][x] = (byte)color;
  57.  
  58.   for ( ; i<s ; i++)
  59.     ngraph_texels[NET_GRAPHHEIGHT - i - 1][x] = (byte)0xff;
  60. }
  61.  
  62. void Draw_CharToNetGraph (int x, int y, int num)
  63. {
  64.   int   row, col;
  65.   byte  *source;
  66.   int   drawline;
  67.   int   nx;
  68.  
  69.   row = num>>4;
  70.   col = num&15;
  71.   source = draw_chars + (row<<10) + (col<<3);
  72.  
  73.   for (drawline = 8; drawline; drawline--, y++)
  74.   {
  75.     for (nx=0 ; nx<8 ; nx++)
  76.       if (source[nx] != 255)
  77.         ngraph_texels[y][nx+x] = 0x60 + source[nx];
  78.     source += 128;
  79.   }
  80. }
  81.  
  82.  
  83. /*
  84. ==============
  85. R_NetGraph
  86. ==============
  87. */
  88. void R_NetGraph (void)
  89. {
  90.   int   a, x, i, y;
  91.   int lost;
  92.   char st[80];
  93.   unsigned  ngraph_pixels[NET_GRAPHHEIGHT][NET_TIMINGS];
  94.  
  95.   x = 0;
  96.   lost = CL_CalcNet();
  97.   for (a=0 ; a<NET_TIMINGS ; a++)
  98.   {
  99.     i = (cls.netchan.outgoing_sequence-a) & NET_TIMINGSMASK;
  100.     R_LineGraph (NET_TIMINGS-1-a, packet_latency[i]);
  101.   }
  102.  
  103.   // now load the netgraph texture into gl and draw it
  104.   for (y = 0; y < NET_GRAPHHEIGHT; y++)
  105.     for (x = 0; x < NET_TIMINGS; x++)
  106.       ngraph_pixels[y][x] = d_8to24table[ngraph_texels[y][x]];
  107.  
  108.   x = -((vid.width - 320)>>1);
  109.   y = vid.height - sb_lines - 24 - NET_GRAPHHEIGHT - 1;
  110.  
  111.   M_DrawTextBox (x, y, NET_TIMINGS/8, NET_GRAPHHEIGHT/8 + 1);
  112.   y += 8;
  113.  
  114.   sprintf(st, "%3i%% packet loss", lost);
  115.   Draw_String(8, y, st);
  116.   y += 8;
  117.   
  118.     GL_Bind(netgraphtexture);
  119.  
  120.   glTexImage2D (GL_TEXTURE_2D, 0, gl_alpha_format, 
  121.     NET_TIMINGS, NET_GRAPHHEIGHT, 0, GL_RGBA, 
  122.     GL_UNSIGNED_BYTE, ngraph_pixels);
  123.  
  124.   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  125.   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  126.   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  127.  
  128.   x = 8;
  129.   glColor3f (1,1,1);
  130.   glBegin (GL_QUADS);
  131.   glTexCoord2f (0, 0);
  132.   glVertex2f (x, y);
  133.   glTexCoord2f (1, 0);
  134.   glVertex2f (x+NET_TIMINGS, y);
  135.   glTexCoord2f (1, 1);
  136.   glVertex2f (x+NET_TIMINGS, y+NET_GRAPHHEIGHT);
  137.   glTexCoord2f (0, 1);
  138.   glVertex2f (x, y+NET_GRAPHHEIGHT);
  139.   glEnd ();
  140. }
  141.  
  142.