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-24 07:36:36 +00:00
|
|
|
int x, y, dx, 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++) {
|
|
|
|
for (y = 0; y < 16; y++) {
|
2001-01-24 18:27:35 +00:00
|
|
|
data[y][x][0] = 255;
|
2001-01-24 07:36:36 +00:00
|
|
|
dx = x - 8;
|
|
|
|
dy = y - 8;
|
|
|
|
d = 255 - 4 * (dx * dx + dy * dy);
|
|
|
|
if (d<0) d = 0;
|
|
|
|
if (d>255) d = 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;
|
|
|
|
float dx, dy;
|
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++)
|
|
|
|
for (x = 0; x < 32; x++) {
|
2001-01-25 04:13:04 +00:00
|
|
|
data[y][x][0] = (noise1[y][x] >> 1) + 128;
|
2000-10-28 08:02:08 +00:00
|
|
|
dx = x - 16;
|
|
|
|
dy = y - 16;
|
|
|
|
d = noise2[y][x] * 4 - 512;
|
|
|
|
if (d > 0) {
|
|
|
|
if (d > 255)
|
|
|
|
d = 255;
|
2000-12-08 06:51:37 +00:00
|
|
|
d = (d * (255 - (int) (dx * dx + dy * dy))) >> 8;
|
|
|
|
if (d < 0)
|
|
|
|
d = 0;
|
|
|
|
if (d > 255)
|
|
|
|
d = 255;
|
2001-01-25 04:13:04 +00:00
|
|
|
data[y][x][1] = (byte) d;
|
2000-12-08 06:51:37 +00:00
|
|
|
} else
|
2001-01-25 04:13:04 +00:00
|
|
|
data[y][x][1] = 0;
|
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
|
|
|
|
|
|
|
}
|
|
|
|
}
|