2000-10-28 08:02:08 +00:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-12-08 06:51:37 +00:00
|
|
|
# include "config.h"
|
2000-10-28 08:02:08 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "fractalnoise.h"
|
|
|
|
#include "glquake.h"
|
|
|
|
|
2000-10-28 08:02:08 +00:00
|
|
|
static void GDT_InitDotParticleTexture (void);
|
|
|
|
static void GDT_InitSmokeParticleTexture (void);
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
int part_tex_smoke[8];
|
|
|
|
int part_tex_dot;
|
2000-10-28 08:02:08 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
GDT_Init (void)
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
GDT_InitDotParticleTexture ();
|
|
|
|
GDT_InitSmokeParticleTexture ();
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
static void
|
|
|
|
GDT_InitDotParticleTexture (void)
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
2001-01-27 03:01:09 +00:00
|
|
|
int x, y, dx2, dy, d;
|
2001-01-25 04:13:04 +00:00
|
|
|
byte data[16][16][2];
|
2000-10-28 08:02:08 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
//
|
2000-10-28 08:02:08 +00:00
|
|
|
// particle texture
|
2000-12-08 06:51:37 +00:00
|
|
|
//
|
2000-10-28 08:02:08 +00:00
|
|
|
part_tex_dot = texture_extension_number++;
|
|
|
|
glBindTexture (GL_TEXTURE_2D, part_tex_dot);
|
|
|
|
|
2001-01-24 06:22:18 +00:00
|
|
|
for (x = 0; x < 16; x++) {
|
2001-01-27 03:01:09 +00:00
|
|
|
dx2 = x - 8;
|
|
|
|
dx2 *= dx2;
|
2001-01-24 06:22:18 +00:00
|
|
|
for (y = 0; y < 16; y++) {
|
2001-01-24 07:36:36 +00:00
|
|
|
dy = y - 8;
|
2001-01-27 03:01:09 +00:00
|
|
|
d = 255 - 4 * (dx2 + dy * dy);
|
2001-01-31 07:52:28 +00:00
|
|
|
if (d<=0) {
|
|
|
|
d = 0;
|
|
|
|
data[y][x][0] = 0;
|
|
|
|
} else
|
|
|
|
data[y][x][0] = 255;
|
|
|
|
|
2001-01-25 04:13:04 +00:00
|
|
|
data[y][x][1] = (byte) d;
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
2001-01-25 04:13:04 +00:00
|
|
|
glTexImage2D (GL_TEXTURE_2D, 0, 2, 16, 16, 0, GL_LUMINANCE_ALPHA,
|
2000-12-08 06:51:37 +00:00
|
|
|
GL_UNSIGNED_BYTE, data);
|
2000-10-28 08:02:08 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
static void
|
|
|
|
GDT_InitSmokeParticleTexture (void)
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i, x, y, d;
|
2001-01-27 03:01:09 +00:00
|
|
|
float dx, dy2;
|
2001-01-25 04:13:04 +00:00
|
|
|
byte data[32][32][2], noise1[32][32], noise2[32][32];
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
fractalnoise (&noise1[0][0], 32);
|
|
|
|
fractalnoise (&noise2[0][0], 32);
|
|
|
|
for (y = 0; y < 32; y++)
|
2001-01-27 03:01:09 +00:00
|
|
|
{
|
|
|
|
dy2 = y - 16;
|
|
|
|
dy2 *= dy2;
|
2000-12-08 06:51:37 +00:00
|
|
|
for (x = 0; x < 32; x++) {
|
2000-10-28 08:02:08 +00:00
|
|
|
dx = x - 16;
|
|
|
|
d = noise2[y][x] * 4 - 512;
|
|
|
|
if (d > 0) {
|
|
|
|
if (d > 255)
|
|
|
|
d = 255;
|
2001-01-27 03:01:09 +00:00
|
|
|
d = (d * (255 - (int) (dx * dx + dy2))) >> 8;
|
2001-01-31 07:52:28 +00:00
|
|
|
if (d <= 0) {
|
2000-12-08 06:51:37 +00:00
|
|
|
d = 0;
|
2001-01-31 07:52:28 +00:00
|
|
|
data[y][x][0] = 0;
|
|
|
|
} else
|
|
|
|
data[y][x][0] = (noise1[y][x] >> 1) + 128;
|
2001-01-27 03:01:09 +00:00
|
|
|
// if (d > 255)
|
|
|
|
// d = 255;
|
2001-01-25 04:13:04 +00:00
|
|
|
data[y][x][1] = (byte) d;
|
2001-01-31 07:52:28 +00:00
|
|
|
} else {
|
|
|
|
data[y][x][0] = 0; //DESPAIR
|
2001-01-25 04:13:04 +00:00
|
|
|
data[y][x][1] = 0;
|
2001-01-31 07:52:28 +00:00
|
|
|
}
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|
2001-01-27 03:01:09 +00:00
|
|
|
}
|
2000-10-28 08:02:08 +00:00
|
|
|
part_tex_smoke[i] = texture_extension_number++;
|
2000-12-08 06:51:37 +00:00
|
|
|
glBindTexture (GL_TEXTURE_2D, part_tex_smoke[i]);
|
|
|
|
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
2001-01-25 04:13:04 +00:00
|
|
|
glTexImage2D (GL_TEXTURE_2D, 0, 2, 32, 32, 0, GL_LUMINANCE_ALPHA,
|
2000-12-08 06:51:37 +00:00
|
|
|
GL_UNSIGNED_BYTE, data);
|
2000-10-28 08:02:08 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|