3 Copyright (c) 2002, Calum Robinson
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
16 * Neither the name of the author nor the names of its contributors may be used
17 to endorse or promote products derived from this software without specific
18 prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
24 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 * Created by calumr on Sat Jul 07 2001.
38 * Copyright (c) 2001 __CompanyName__. All rights reserved.
54 static GLubyte smallTextureArray[32][32];
55 static GLubyte bigTextureArray[256][256][2];
56 GLuint theTexture = 0;
58 /* simple smoothing routine */
59 static void SmoothTexture(void)
61 GLubyte filter[32][32];
68 t = (float) smallTextureArray[i][j]*4;
69 t += (float) smallTextureArray[i-1][j];
70 t += (float) smallTextureArray[i+1][j];
71 t += (float) smallTextureArray[i][j-1];
72 t += (float) smallTextureArray[i][j+1];
74 filter[i][j] = (GLubyte) t;
81 smallTextureArray[i][j] = filter[i][j];
86 /* add some randomness to texture data */
87 static void SpeckleTexture(void)
97 while (speck <= 32 && random() % 2)
99 t = (float) MIN_(255,smallTextureArray[i][j]+speck);
100 smallTextureArray[i][j] = (GLubyte) t;
104 while (speck <= 32 && random() % 2)
106 t = (float) MAX_(0,smallTextureArray[i][j]-speck);
107 smallTextureArray[i][j] = (GLubyte) t;
114 static void MakeSmallTexture(void)
116 static int firstTime = 1;
126 r = (float) sqrt((i-15.5)*(i-15.5)+(j-15.5)*(j-15.5));
129 smallTextureArray[i][j] = 0;
133 t = 255.0f * (float) cos(r*M_PI/31.0);
134 smallTextureArray[i][j] = (GLubyte) t;
145 r = (float) sqrt((i-15.5)*(i-15.5)+(j-15.5)*(j-15.5));
152 t = 255.0f * (float) cos(r*M_PI/31.0);
154 smallTextureArray[i][j] = (GLubyte) MIN_(255,(t+smallTextureArray[i][j]+smallTextureArray[i][j])/3);
163 static void CopySmallTextureToBigTexture(int k, int l)
170 bigTextureArray[i+k][j+l][0] = smallTextureArray[i][j];
171 bigTextureArray[i+k][j+l][1] = smallTextureArray[i][j];
176 static void AverageLastAndFirstTextures(void)
184 t = (smallTextureArray[i][j] + bigTextureArray[i][j][0]) / 2;
185 smallTextureArray[i][j] = (GLubyte) MIN_(255,t);
199 AverageLastAndFirstTextures();
205 CopySmallTextureToBigTexture(i*32,j*32);
209 glPixelStorei(GL_UNPACK_ALIGNMENT,1);
211 glGenTextures(1, &theTexture);
212 glBindTexture(GL_TEXTURE_2D, theTexture);
214 /* Set the tiling mode (this is generally always GL_REPEAT). */
215 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
216 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
218 /* Set the filtering. */
219 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
220 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
222 gluBuild2DMipmaps(GL_TEXTURE_2D, 2, 256, 256, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, bigTextureArray);
223 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);