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.
50 static GLubyte smallTextureArray[32][32];
51 static GLubyte bigTextureArray[256][256][2];
52 GLuint theTexture = 0;
54 /* simple smoothing routine */
55 static void SmoothTexture(void)
57 GLubyte filter[32][32];
64 t = (float) smallTextureArray[i][j]*4;
65 t += (float) smallTextureArray[i-1][j];
66 t += (float) smallTextureArray[i+1][j];
67 t += (float) smallTextureArray[i][j-1];
68 t += (float) smallTextureArray[i][j+1];
70 filter[i][j] = (GLubyte) t;
77 smallTextureArray[i][j] = filter[i][j];
82 /* add some randomness to texture data */
83 static void SpeckleTexture(void)
93 while (speck <= 32 && random() % 2)
95 t = (float) MIN_(255,smallTextureArray[i][j]+speck);
96 smallTextureArray[i][j] = (GLubyte) t;
100 while (speck <= 32 && random() % 2)
102 t = (float) MAX_(0,smallTextureArray[i][j]-speck);
103 smallTextureArray[i][j] = (GLubyte) t;
110 static void MakeSmallTexture(void)
112 static int firstTime = 1;
122 r = (float) sqrt((i-15.5)*(i-15.5)+(j-15.5)*(j-15.5));
125 smallTextureArray[i][j] = 0;
129 t = 255.0f * (float) cos(r*M_PI/31.0);
130 smallTextureArray[i][j] = (GLubyte) t;
141 r = (float) sqrt((i-15.5)*(i-15.5)+(j-15.5)*(j-15.5));
148 t = 255.0f * (float) cos(r*M_PI/31.0);
150 smallTextureArray[i][j] = (GLubyte) MIN_(255,(t+smallTextureArray[i][j]+smallTextureArray[i][j])/3);
159 static void CopySmallTextureToBigTexture(int k, int l)
166 bigTextureArray[i+k][j+l][0] = smallTextureArray[i][j];
167 bigTextureArray[i+k][j+l][1] = smallTextureArray[i][j];
172 static void AverageLastAndFirstTextures(void)
180 t = (smallTextureArray[i][j] + bigTextureArray[i][j][0]) / 2;
181 smallTextureArray[i][j] = (GLubyte) MIN_(255,t);
195 AverageLastAndFirstTextures();
201 CopySmallTextureToBigTexture(i*32,j*32);
205 glPixelStorei(GL_UNPACK_ALIGNMENT,1);
207 glGenTextures(1, &theTexture);
208 glBindTexture(GL_TEXTURE_2D, theTexture);
210 /* Set the tiling mode (this is generally always GL_REPEAT). */
211 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
212 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
214 /* Set the filtering. */
215 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
216 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
218 gluBuild2DMipmaps(GL_TEXTURE_2D, 2, 256, 256, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, bigTextureArray);
219 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);