gl_rmisc.c (5825B)
1 /* 2 Copyright (C) 1997-2001 Id Software, Inc. 3 4 This program is free software; you can redistribute it and/or 5 modify it under the terms of the GNU General Public License 6 as published by the Free Software Foundation; either version 2 7 of the License, or (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 13 See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19 */ 20 // r_misc.c 21 22 #include "gl_local.h" 23 24 /* 25 ================== 26 R_InitParticleTexture 27 ================== 28 */ 29 byte dottexture[8][8] = 30 { 31 {0,0,0,0,0,0,0,0}, 32 {0,0,1,1,0,0,0,0}, 33 {0,1,1,1,1,0,0,0}, 34 {0,1,1,1,1,0,0,0}, 35 {0,0,1,1,0,0,0,0}, 36 {0,0,0,0,0,0,0,0}, 37 {0,0,0,0,0,0,0,0}, 38 {0,0,0,0,0,0,0,0}, 39 }; 40 41 void R_InitParticleTexture (void) 42 { 43 int x,y; 44 byte data[8][8][4]; 45 46 // 47 // particle texture 48 // 49 for (x=0 ; x<8 ; x++) 50 { 51 for (y=0 ; y<8 ; y++) 52 { 53 data[y][x][0] = 255; 54 data[y][x][1] = 255; 55 data[y][x][2] = 255; 56 data[y][x][3] = dottexture[x][y]*255; 57 } 58 } 59 r_particletexture = GL_LoadPic ("***particle***", (byte *)data, 8, 8, it_sprite, 32); 60 61 // 62 // also use this for bad textures, but without alpha 63 // 64 for (x=0 ; x<8 ; x++) 65 { 66 for (y=0 ; y<8 ; y++) 67 { 68 data[y][x][0] = dottexture[x&3][y&3]*255; 69 data[y][x][1] = 0; // dottexture[x&3][y&3]*255; 70 data[y][x][2] = 0; //dottexture[x&3][y&3]*255; 71 data[y][x][3] = 255; 72 } 73 } 74 r_notexture = GL_LoadPic ("***r_notexture***", (byte *)data, 8, 8, it_wall, 32); 75 } 76 77 78 /* 79 ============================================================================== 80 81 SCREEN SHOTS 82 83 ============================================================================== 84 */ 85 86 typedef struct _TargaHeader { 87 unsigned char id_length, colormap_type, image_type; 88 unsigned short colormap_index, colormap_length; 89 unsigned char colormap_size; 90 unsigned short x_origin, y_origin, width, height; 91 unsigned char pixel_size, attributes; 92 } TargaHeader; 93 94 95 /* 96 ================== 97 GL_ScreenShot_f 98 ================== 99 */ 100 void GL_ScreenShot_f (void) 101 { 102 byte *buffer; 103 char picname[80]; 104 char checkname[MAX_OSPATH]; 105 int i, c, temp; 106 FILE *f; 107 108 // create the scrnshots directory if it doesn't exist 109 Com_sprintf (checkname, sizeof(checkname), "%s/scrnshot", ri.FS_Gamedir()); 110 Sys_Mkdir (checkname); 111 112 // 113 // find a file name to save it to 114 // 115 strcpy(picname,"quake00.tga"); 116 117 for (i=0 ; i<=99 ; i++) 118 { 119 picname[5] = i/10 + '0'; 120 picname[6] = i%10 + '0'; 121 Com_sprintf (checkname, sizeof(checkname), "%s/scrnshot/%s", ri.FS_Gamedir(), picname); 122 f = fopen (checkname, "rb"); 123 if (!f) 124 break; // file doesn't exist 125 fclose (f); 126 } 127 if (i==100) 128 { 129 ri.Con_Printf (PRINT_ALL, "SCR_ScreenShot_f: Couldn't create a file\n"); 130 return; 131 } 132 133 134 buffer = malloc(vid.width*vid.height*3 + 18); 135 memset (buffer, 0, 18); 136 buffer[2] = 2; // uncompressed type 137 buffer[12] = vid.width&255; 138 buffer[13] = vid.width>>8; 139 buffer[14] = vid.height&255; 140 buffer[15] = vid.height>>8; 141 buffer[16] = 24; // pixel size 142 143 qglReadPixels (0, 0, vid.width, vid.height, GL_RGB, GL_UNSIGNED_BYTE, buffer+18 ); 144 145 // swap rgb to bgr 146 c = 18+vid.width*vid.height*3; 147 for (i=18 ; i<c ; i+=3) 148 { 149 temp = buffer[i]; 150 buffer[i] = buffer[i+2]; 151 buffer[i+2] = temp; 152 } 153 154 f = fopen (checkname, "wb"); 155 fwrite (buffer, 1, c, f); 156 fclose (f); 157 158 free (buffer); 159 ri.Con_Printf (PRINT_ALL, "Wrote %s\n", picname); 160 } 161 162 /* 163 ** GL_Strings_f 164 */ 165 void GL_Strings_f( void ) 166 { 167 ri.Con_Printf (PRINT_ALL, "GL_VENDOR: %s\n", gl_config.vendor_string ); 168 ri.Con_Printf (PRINT_ALL, "GL_RENDERER: %s\n", gl_config.renderer_string ); 169 ri.Con_Printf (PRINT_ALL, "GL_VERSION: %s\n", gl_config.version_string ); 170 ri.Con_Printf (PRINT_ALL, "GL_EXTENSIONS: %s\n", gl_config.extensions_string ); 171 } 172 173 /* 174 ** GL_SetDefaultState 175 */ 176 void GL_SetDefaultState( void ) 177 { 178 qglClearColor (1,0, 0.5 , 0.5); 179 qglCullFace(GL_FRONT); 180 qglEnable(GL_TEXTURE_2D); 181 182 qglEnable(GL_ALPHA_TEST); 183 qglAlphaFunc(GL_GREATER, 0.666); 184 185 qglDisable (GL_DEPTH_TEST); 186 qglDisable (GL_CULL_FACE); 187 qglDisable (GL_BLEND); 188 189 qglColor4f (1,1,1,1); 190 191 qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 192 qglShadeModel (GL_FLAT); 193 194 GL_TextureMode( gl_texturemode->string ); 195 GL_TextureAlphaMode( gl_texturealphamode->string ); 196 GL_TextureSolidMode( gl_texturesolidmode->string ); 197 198 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_min); 199 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max); 200 201 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 202 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 203 204 qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 205 206 GL_TexEnv( GL_REPLACE ); 207 208 if ( qglPointParameterfEXT ) 209 { 210 float attenuations[3]; 211 212 attenuations[0] = gl_particle_att_a->value; 213 attenuations[1] = gl_particle_att_b->value; 214 attenuations[2] = gl_particle_att_c->value; 215 216 qglEnable( GL_POINT_SMOOTH ); 217 qglPointParameterfEXT( GL_POINT_SIZE_MIN_EXT, gl_particle_min_size->value ); 218 qglPointParameterfEXT( GL_POINT_SIZE_MAX_EXT, gl_particle_max_size->value ); 219 qglPointParameterfvEXT( GL_DISTANCE_ATTENUATION_EXT, attenuations ); 220 } 221 222 if ( qglColorTableEXT && gl_ext_palettedtexture->value ) 223 { 224 qglEnable( GL_SHARED_TEXTURE_PALETTE_EXT ); 225 226 GL_SetTexturePalette( d_8to24table ); 227 } 228 229 GL_UpdateSwapInterval(); 230 } 231 232 void GL_UpdateSwapInterval( void ) 233 { 234 if ( gl_swapinterval->modified ) 235 { 236 gl_swapinterval->modified = false; 237 238 if ( !gl_state.stereo_enabled ) 239 { 240 #ifdef _WIN32 241 if ( qwglSwapIntervalEXT ) 242 qwglSwapIntervalEXT( gl_swapinterval->value ); 243 #endif 244 } 245 } 246 }