2001-05-22 06:00:38 +00:00
|
|
|
/*
|
2001-11-24 08:16:43 +00:00
|
|
|
gl_graph.c
|
2001-05-22 06:00:38 +00:00
|
|
|
|
|
|
|
(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
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$Id$";
|
|
|
|
|
2001-05-22 06:00:38 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2001-09-01 08:57:04 +00:00
|
|
|
#include <stdlib.h>
|
2001-05-22 06:00:38 +00:00
|
|
|
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/draw.h"
|
2003-01-06 18:28:13 +00:00
|
|
|
#include "QF/render.h"
|
2001-05-22 06:00:38 +00:00
|
|
|
#include "QF/sys.h"
|
2001-08-22 11:00:25 +00:00
|
|
|
#include "QF/GL/defines.h"
|
|
|
|
#include "QF/GL/funcs.h"
|
2001-09-01 08:57:04 +00:00
|
|
|
#include "QF/GL/qf_textures.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-09-01 08:57:04 +00:00
|
|
|
static byte *graph_texels[NUM_GRAPH_TEXTURES];
|
|
|
|
int graph_texture[NUM_GRAPH_TEXTURES];
|
|
|
|
static int graph_index;
|
|
|
|
static int graph_size[NUM_GRAPH_TEXTURES];
|
|
|
|
static int graph_width[NUM_GRAPH_TEXTURES];
|
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)
|
|
|
|
{
|
|
|
|
byte color;
|
|
|
|
byte *dest;
|
2001-09-01 08:57:04 +00:00
|
|
|
int size, h, i, j, s;
|
2001-05-22 06:00:38 +00:00
|
|
|
|
|
|
|
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])
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("R_LineGraph: failed to allocate texture buffer");
|
2001-05-22 06:00:38 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|