gl_ngraph.c 3.2 KB

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