gl_rmisc.c 5.7 KB

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