quakeforge/libs/video/renderer/gl/gl_dyn_textures.c
2001-09-28 06:26:31 +00:00

152 lines
3.6 KiB
C

/*
gl_dyn_textures.c
Dynamic texture generation.
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
*/
static const char rcsid[] =
"$Id$";
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include "QF/qtypes.h"
#include "QF/GL/defines.h"
#include "QF/GL/funcs.h"
#include "QF/GL/qf_vid.h"
int part_tex_dot;
int part_tex_smoke;
int part_tex_spark;
extern void noise_diamondsquare(unsigned char *noise, int size);
extern void noise_plasma(unsigned char *noise, int size);
static void
GDT_InitDotParticleTexture (void)
{
byte data[16][16][2];
int x, y, dx2, dy, d;
for (x = 0; x < 16; x++) {
dx2 = x - 8;
dx2 *= dx2;
for (y = 0; y < 16; y++) {
dy = y - 8;
d = 255 - 4 * (dx2 + (dy * dy));
if (d<=0) {
d = 0;
data[y][x][0] = 0;
} else
data[y][x][0] = 255;
data[y][x][1] = (byte) d;
}
}
part_tex_dot = texture_extension_number++;
qfglBindTexture (GL_TEXTURE_2D, part_tex_dot);
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
qfglTexImage2D (GL_TEXTURE_2D, 0, 2, 16, 16, 0, GL_LUMINANCE_ALPHA,
GL_UNSIGNED_BYTE, data);
}
static void
GDT_InitSparkParticleTexture (void)
{
byte data[16][16][2];
int x, y, dx2, dy, d;
for (x = 0; x < 16; x++) {
dx2 = 8 - abs(x - 8);
dx2 *= dx2;
for (y = 0; y < 16; y++) {
dy = 8 - abs(y - 8);
d = 3 * (dx2 + dy * dy) - 100;
if (d>255)
d = 255;
if (d<1) {
d = 0;
data[y][x][0] = 0;
} else
data[y][x][0] = 255;
data[y][x][1] = (byte) d;
}
}
part_tex_spark = texture_extension_number++;
qfglBindTexture (GL_TEXTURE_2D, part_tex_spark);
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
qfglTexImage2D (GL_TEXTURE_2D, 0, 2, 16, 16, 0, GL_LUMINANCE_ALPHA,
GL_UNSIGNED_BYTE, data);
}
static void
GDT_InitSmokeParticleTexture (void)
{
byte d;
byte data[32][32][2], noise1[32][32], noise2[32][32];
float dx, dy2;
int x, y, c;
noise_plasma (&noise1[0][0], 32);
noise_diamondsquare (&noise2[0][0], 32);
for (y = 0; y < 32; y++)
{
dy2 = y - 16;
dy2 *= dy2;
for (x = 0; x < 32; x++) {
dx = x - 16;
c = 255 - (dx*dx + dy2);
if (c < 1)
c = 0;
d = (noise1[y][x] + noise2[y][x]) / 2;
if (d > 0) {
data[y][x][0] = 255;
data[y][x][1] = (d * c)/255;
} else {
data[y][x][0] = 255;
data[y][x][1] = 0;
}
}
}
part_tex_smoke = texture_extension_number++;
qfglBindTexture (GL_TEXTURE_2D, part_tex_smoke);
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
qfglTexImage2D (GL_TEXTURE_2D, 0, 2, 32, 32, 0, GL_LUMINANCE_ALPHA,
GL_UNSIGNED_BYTE, data);
}
void
GDT_Init (void)
{
GDT_InitDotParticleTexture ();
GDT_InitSparkParticleTexture ();
GDT_InitSmokeParticleTexture ();
}