vkQuake2 doxygen  1.0 dev
gl_rmisc.c
Go to the documentation of this file.
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 
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 
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 
227  }
228 
230 }
231 
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 }
it_sprite
@ it_sprite
Definition: r_local.h:65
GL_LoadPic
image_t * GL_LoadPic(char *name, byte *pic, int width, int height, imagetype_t type)
Definition: r_image.c:414
GL_UpdateSwapInterval
void GL_UpdateSwapInterval(void)
Definition: gl_rmisc.c:232
glstate_t::stereo_enabled
qboolean stereo_enabled
Definition: gl_local.h:422
GL_SetDefaultState
void GL_SetDefaultState(void)
Definition: gl_rmisc.c:176
gl_particle_att_c
cvar_t * gl_particle_att_c
Definition: gl_rmain.c:101
_TargaHeader::y_origin
unsigned short y_origin
Definition: r_image.c:194
r_notexture
image_t * r_notexture
Definition: gl_rmain.c:44
R_InitParticleTexture
void R_InitParticleTexture(void)
Definition: gl_rmisc.c:41
GL_SHARED_TEXTURE_PALETTE_EXT
#define GL_SHARED_TEXTURE_PALETTE_EXT
Definition: qgl.h:476
gl_state
glstate_t gl_state
Definition: gl_rmain.c:42
ri
refimport_t ri
Definition: r_main.c:25
Sys_Mkdir
void Sys_Mkdir(char *path)
Definition: q_shwin.c:135
GL_TextureAlphaMode
void GL_TextureAlphaMode(char *string)
Definition: gl_image.c:255
glconfig_t::extensions_string
const char * extensions_string
Definition: gl_local.h:402
it_wall
@ it_wall
Definition: r_local.h:66
cvar_s::modified
qboolean modified
Definition: q_shared.h:330
_TargaHeader::x_origin
unsigned short x_origin
Definition: r_image.c:194
GL_TextureMode
void GL_TextureMode(char *string)
Definition: gl_image.c:218
_TargaHeader::pixel_size
unsigned char pixel_size
Definition: r_image.c:195
cvar_s::string
char * string
Definition: q_shared.h:327
x
GLint GLenum GLint x
Definition: qgl_win.c:116
i
int i
Definition: q_shared.c:305
gl_particle_att_a
cvar_t * gl_particle_att_a
Definition: gl_rmain.c:99
buffer
GLenum GLfloat * buffer
Definition: qgl_win.c:151
_TargaHeader::image_type
unsigned char image_type
Definition: r_image.c:191
_TargaHeader::colormap_size
unsigned char colormap_size
Definition: r_image.c:193
_TargaHeader::colormap_index
unsigned short colormap_index
Definition: r_image.c:192
GL_TextureSolidMode
void GL_TextureSolidMode(char *string)
Definition: gl_image.c:279
gl_filter_min
int gl_filter_min
Definition: gl_image.c:45
gl_texturemode
cvar_t * gl_texturemode
Definition: gl_rmain.c:133
GL_ScreenShot_f
void GL_ScreenShot_f(void)
Definition: gl_rmisc.c:100
refimport_t::Con_Printf
void(* Con_Printf)(int print_level, char *str,...)
Definition: ref.h:202
PRINT_ALL
#define PRINT_ALL
Definition: qcommon.h:751
gl_texturealphamode
cvar_t * gl_texturealphamode
Definition: gl_rmain.c:134
viddef_t::width
unsigned width
Definition: vid.h:29
_TargaHeader::colormap_length
unsigned short colormap_length
Definition: r_image.c:192
viddef_t::height
unsigned height
Definition: vid.h:29
_TargaHeader::attributes
unsigned char attributes
Definition: r_image.c:195
cvar_s::value
float value
Definition: q_shared.h:331
r_particletexture
image_t * r_particletexture
Definition: gl_rmain.c:45
MAX_OSPATH
#define MAX_OSPATH
Definition: q_shared.h:81
refimport_t::FS_Gamedir
char *(* FS_Gamedir)(void)
Definition: ref.h:214
dottexture
byte dottexture[8][8]
Definition: gl_rmisc.c:29
GL_DISTANCE_ATTENUATION_EXT
#define GL_DISTANCE_ATTENUATION_EXT
Definition: qgl.h:471
GL_SetTexturePalette
void GL_SetTexturePalette(unsigned palette[256])
Definition: gl_image.c:48
gl_filter_max
int gl_filter_max
Definition: gl_image.c:46
glconfig_t::renderer_string
const char * renderer_string
Definition: gl_local.h:399
y
GLint y
Definition: qgl_win.c:115
_TargaHeader
Definition: r_image.c:190
gl_texturesolidmode
cvar_t * gl_texturesolidmode
Definition: gl_rmain.c:135
gl_particle_max_size
cvar_t * gl_particle_max_size
Definition: gl_rmain.c:97
GL_POINT_SIZE_MAX_EXT
#define GL_POINT_SIZE_MAX_EXT
Definition: qgl.h:469
d_8to24table
unsigned d_8to24table[256]
Definition: r_main.c:27
gl_config
glconfig_t gl_config
Definition: gl_rmain.c:41
GL_TexEnv
void GL_TexEnv(GLenum mode)
Definition: gl_image.c:126
gl_local.h
gl_ext_palettedtexture
static cvar_t * gl_ext_palettedtexture
Definition: vid_menu.c:40
_TargaHeader::colormap_type
unsigned char colormap_type
Definition: r_image.c:191
_TargaHeader::width
unsigned short width
Definition: r_image.c:194
glconfig_t::vendor_string
const char * vendor_string
Definition: gl_local.h:400
_TargaHeader::id_length
unsigned char id_length
Definition: r_image.c:191
TargaHeader
struct _TargaHeader TargaHeader
_TargaHeader::height
unsigned short height
Definition: r_image.c:194
GL_POINT_SIZE_MIN_EXT
#define GL_POINT_SIZE_MIN_EXT
Definition: qgl.h:468
gl_particle_min_size
cvar_t * gl_particle_min_size
Definition: gl_rmain.c:96
GL_Strings_f
void GL_Strings_f(void)
Definition: gl_rmisc.c:165
gl_swapinterval
cvar_t * gl_swapinterval
Definition: gl_rmain.c:132
glconfig_t::version_string
const char * version_string
Definition: gl_local.h:401
Com_sprintf
void Com_sprintf(char *dest, int size, char *fmt,...)
Definition: q_shared.c:1223
gl_particle_att_b
cvar_t * gl_particle_att_b
Definition: gl_rmain.c:100
vid
viddef_t vid
Definition: r_main.c:24