2001-05-22 06:00:38 +00:00
|
|
|
/*
|
|
|
|
gl_ngraph.c
|
|
|
|
|
|
|
|
(description)
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/draw.h"
|
|
|
|
#include "QF/sys.h"
|
2001-08-22 11:00:25 +00:00
|
|
|
#include "QF/GL/qf_textures.h"
|
|
|
|
#include "QF/GL/defines.h"
|
|
|
|
#include "QF/GL/funcs.h"
|
2001-05-22 06:00:38 +00:00
|
|
|
|
|
|
|
#include "r_cvar.h"
|
|
|
|
|
2001-06-24 09:25:55 +00:00
|
|
|
#define NUM_GRAPH_TEXTURES 8
|
|
|
|
|
2001-05-22 06:00:38 +00:00
|
|
|
extern byte *draw_chars; // 8*8 graphic characters
|
|
|
|
|
|
|
|
extern cvar_t *r_netgraph;
|
|
|
|
extern cvar_t *r_netgraph_alpha;
|
|
|
|
extern cvar_t *r_netgraph_box;
|
|
|
|
|
|
|
|
static int graph_index;
|
|
|
|
static int graph_size[NUM_GRAPH_TEXTURES];
|
|
|
|
static int graph_width[NUM_GRAPH_TEXTURES];
|
|
|
|
static byte *graph_texels[NUM_GRAPH_TEXTURES];
|
|
|
|
int graph_texture[NUM_GRAPH_TEXTURES];
|
|
|
|
|
2001-08-22 11:00:25 +00:00
|
|
|
|
2001-05-22 06:00:38 +00:00
|
|
|
int
|
|
|
|
R_InitGraphTextures (int base)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_GRAPH_TEXTURES; i++)
|
|
|
|
graph_texture[i] = base++;
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
R_LineGraph (int x, int y, int *h_vals, int count)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
int h;
|
|
|
|
int s;
|
|
|
|
byte color;
|
|
|
|
int size;
|
|
|
|
byte *dest;
|
|
|
|
|
|
|
|
if (!count)
|
|
|
|
return;
|
|
|
|
|
|
|
|
s = r_graphheight->int_val;
|
|
|
|
|
2001-05-23 03:33:39 +00:00
|
|
|
size = s * count;
|
2001-05-22 06:00:38 +00:00
|
|
|
if (size > graph_size[graph_index]) {
|
|
|
|
graph_size[graph_index] = size;
|
|
|
|
graph_texels[graph_index] = realloc (graph_texels[graph_index], size);
|
|
|
|
}
|
|
|
|
graph_width[graph_index] = count;
|
|
|
|
|
|
|
|
if (!graph_texels[graph_index])
|
|
|
|
Sys_Error ("R_LineGraph: failed to allocate texture buffer\n");
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (count--) {
|
|
|
|
dest = graph_texels[graph_index] + i++;
|
|
|
|
|
|
|
|
h = *h_vals++;
|
|
|
|
|
|
|
|
if (h == 10000)
|
|
|
|
color = 0x6f; // yellow
|
|
|
|
else if (h == 9999)
|
|
|
|
color = 0x4f; // red
|
|
|
|
else if (h == 9998)
|
|
|
|
color = 0xd0; // blue
|
|
|
|
else
|
|
|
|
color = 0xfe; // white
|
|
|
|
|
|
|
|
if (h > s)
|
|
|
|
h = s;
|
|
|
|
|
|
|
|
for (j = 0; j < h; j++, dest += graph_width[graph_index])
|
|
|
|
dest[0] = color;
|
|
|
|
|
|
|
|
for (; j < s; j++, dest += graph_width[graph_index])
|
|
|
|
dest[0] = 0xff;
|
|
|
|
}
|
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, graph_texture[graph_index]);
|
2001-05-22 06:00:38 +00:00
|
|
|
|
2001-05-23 03:33:39 +00:00
|
|
|
GL_Upload8 (graph_texels[graph_index], graph_width[graph_index], s, 0, 1);
|
2001-05-22 06:00:38 +00:00
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBegin (GL_QUADS);
|
|
|
|
qfglTexCoord2f (0, 0);
|
|
|
|
qfglVertex2f (x, y);
|
|
|
|
qfglTexCoord2f (1, 0);
|
|
|
|
qfglVertex2f (x + graph_width[graph_index], y);
|
|
|
|
qfglTexCoord2f (1, 1);
|
|
|
|
qfglVertex2f (x + graph_width[graph_index], y - s);
|
|
|
|
qfglTexCoord2f (0, 1);
|
|
|
|
qfglVertex2f (x, y - s);
|
|
|
|
qfglEnd ();
|
|
|
|
|
2001-05-22 06:00:38 +00:00
|
|
|
graph_index = (graph_index + 1) % NUM_GRAPH_TEXTURES;
|
|
|
|
}
|