vkQuake2 doxygen  1.0 dev
gl_draw.c File Reference
#include "gl_local.h"

Go to the source code of this file.

Functions

void Scrap_Upload (void)
 
void Draw_InitLocal (void)
 
void Draw_Char (int x, int y, int num)
 
image_tDraw_FindPic (char *name)
 
void Draw_GetPicSize (int *w, int *h, char *pic)
 
void Draw_StretchPic (int x, int y, int w, int h, char *pic)
 
void Draw_Pic (int x, int y, char *pic)
 
void Draw_TileClear (int x, int y, int w, int h, char *pic)
 
void Draw_Fill (int x, int y, int w, int h, int c)
 
void Draw_FadeScreen (void)
 
void Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, byte *data)
 

Variables

image_tdraw_chars
 
qboolean scrap_dirty
 
unsigned r_rawpalette [256]
 

Function Documentation

◆ Draw_Char()

void Draw_Char ( int  x,
int  y,
int  num 
)

Definition at line 56 of file gl_draw.c.

57 {
58  int row, col;
59  float frow, fcol, size;
60 
61  num &= 255;
62 
63  if ( (num&127) == 32 )
64  return; // space
65 
66  if (y <= -8)
67  return; // totally off screen
68 
69  cvar_t *scale = ri.Cvar_Get("hudscale", "1", 0);
70 
71  row = num>>4;
72  col = num&15;
73 
74  frow = row*0.0625;
75  fcol = col*0.0625;
76  size = 0.0625;
77 
79 
80  qglBegin (GL_QUADS);
81  qglTexCoord2f (fcol, frow);
82  qglVertex2f (x, y);
83  qglTexCoord2f (fcol + size, frow);
84  qglVertex2f (x+8*scale->value, y);
85  qglTexCoord2f (fcol + size, frow + size);
86  qglVertex2f (x+8*scale->value, y+8*scale->value);
87  qglTexCoord2f (fcol, frow + size);
88  qglVertex2f (x, y+8*scale->value);
89  qglEnd ();
90 }

◆ Draw_FadeScreen()

void Draw_FadeScreen ( void  )

Definition at line 296 of file gl_draw.c.

297 {
298  qglEnable (GL_BLEND);
299  qglDisable (GL_TEXTURE_2D);
300  qglColor4f (0, 0, 0, 0.8);
301  qglBegin (GL_QUADS);
302 
303  qglVertex2f (0,0);
304  qglVertex2f (vid.width, 0);
305  qglVertex2f (vid.width, vid.height);
306  qglVertex2f (0, vid.height);
307 
308  qglEnd ();
309  qglColor4f (1,1,1,1);
310  qglEnable (GL_TEXTURE_2D);
311  qglDisable (GL_BLEND);
312 }

◆ Draw_Fill()

void Draw_Fill ( int  x,
int  y,
int  w,
int  h,
int  c 
)

Definition at line 258 of file gl_draw.c.

259 {
260  union
261  {
262  unsigned c;
263  byte v[4];
264  } color;
265 
266  if ( (unsigned)c > 255)
267  ri.Sys_Error (ERR_FATAL, "Draw_Fill: bad color");
268 
269  qglDisable (GL_TEXTURE_2D);
270 
271  color.c = d_8to24table[c];
272  qglColor3f (color.v[0]/255.0,
273  color.v[1]/255.0,
274  color.v[2]/255.0);
275 
276  qglBegin (GL_QUADS);
277 
278  qglVertex2f (x,y);
279  qglVertex2f (x+w, y);
280  qglVertex2f (x+w, y+h);
281  qglVertex2f (x, y+h);
282 
283  qglEnd ();
284  qglColor3f (1,1,1);
285  qglEnable (GL_TEXTURE_2D);
286 }

◆ Draw_FindPic()

image_t* Draw_FindPic ( char *  name)

Definition at line 97 of file gl_draw.c.

98 {
99  image_t *gl;
100  char fullname[MAX_QPATH];
101 
102  if (name[0] != '/' && name[0] != '\\')
103  {
104  Com_sprintf (fullname, sizeof(fullname), "pics/%s.pcx", name);
105  gl = GL_FindImage (fullname, it_pic);
106  }
107  else
108  gl = GL_FindImage (name+1, it_pic);
109 
110  return gl;
111 }

Referenced by Draw_GetPicSize(), Draw_Pic(), Draw_StretchPic(), and Draw_TileClear().

◆ Draw_GetPicSize()

void Draw_GetPicSize ( int w,
int h,
char *  pic 
)

Definition at line 118 of file gl_draw.c.

119 {
120  image_t *gl;
121 
122  gl = Draw_FindPic (pic);
123  if (!gl)
124  {
125  *w = *h = -1;
126  return;
127  }
128 
129  cvar_t *scale = ri.Cvar_Get("hudscale", "1", 0);
130 
131  *w = gl->width * scale->value;
132  *h = gl->height * scale->value;
133 }

◆ Draw_InitLocal()

void Draw_InitLocal ( void  )

Definition at line 36 of file gl_draw.c.

37 {
38  // load console characters (don't bilerp characters)
39  draw_chars = GL_FindImage ("pics/conchars.pcx", it_pic);
41  qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
42  qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
43 }

◆ Draw_Pic()

void Draw_Pic ( int  x,
int  y,
char *  pic 
)

Definition at line 179 of file gl_draw.c.

180 {
181  image_t *gl;
182  cvar_t *scale = ri.Cvar_Get("hudscale", "1", 0);
183 
184  gl = Draw_FindPic (pic);
185  if (!gl)
186  {
187  ri.Con_Printf (PRINT_ALL, "Can't find pic: %s\n", pic);
188  return;
189  }
190  if (scrap_dirty)
191  Scrap_Upload ();
192 
194  qglDisable (GL_ALPHA_TEST);
195 
196  GL_Bind (gl->texnum);
197  qglBegin (GL_QUADS);
198  qglTexCoord2f (gl->sl, gl->tl);
199  qglVertex2f (x, y);
200  qglTexCoord2f (gl->sh, gl->tl);
201  qglVertex2f (x+gl->width*scale->value, y);
202  qglTexCoord2f (gl->sh, gl->th);
203  qglVertex2f (x+gl->width*scale->value, y+gl->height*scale->value);
204  qglTexCoord2f (gl->sl, gl->th);
205  qglVertex2f (x, y+gl->height*scale->value);
206  qglEnd ();
207 
209  qglEnable (GL_ALPHA_TEST);
210 }

◆ Draw_StretchPic()

void Draw_StretchPic ( int  x,
int  y,
int  w,
int  h,
char *  pic 
)

Definition at line 140 of file gl_draw.c.

141 {
142  image_t *gl;
143 
144  gl = Draw_FindPic (pic);
145  if (!gl)
146  {
147  ri.Con_Printf (PRINT_ALL, "Can't find pic: %s\n", pic);
148  return;
149  }
150 
151  if (scrap_dirty)
152  Scrap_Upload ();
153 
155  qglDisable (GL_ALPHA_TEST);
156 
157  GL_Bind (gl->texnum);
158  qglBegin (GL_QUADS);
159  qglTexCoord2f (gl->sl, gl->tl);
160  qglVertex2f (x, y);
161  qglTexCoord2f (gl->sh, gl->tl);
162  qglVertex2f (x+w, y);
163  qglTexCoord2f (gl->sh, gl->th);
164  qglVertex2f (x+w, y+h);
165  qglTexCoord2f (gl->sl, gl->th);
166  qglVertex2f (x, y+h);
167  qglEnd ();
168 
170  qglEnable (GL_ALPHA_TEST);
171 }

◆ Draw_StretchRaw()

void Draw_StretchRaw ( int  x,
int  y,
int  w,
int  h,
int  cols,
int  rows,
byte data 
)

Definition at line 325 of file gl_draw.c.

326 {
327  unsigned image32[256*256];
328  unsigned char image8[256*256];
329  int i, j, trows;
330  byte *source;
331  int frac, fracstep;
332  float hscale;
333  int row;
334  float t;
335 
336  GL_Bind (0);
337 
338  if (rows<=256)
339  {
340  hscale = 1;
341  trows = rows;
342  }
343  else
344  {
345  hscale = rows/256.0;
346  trows = 256;
347  }
348  t = rows*hscale / 256;
349 
350  if ( !qglColorTableEXT )
351  {
352  unsigned *dest;
353 
354  for (i=0 ; i<trows ; i++)
355  {
356  row = (int)(i*hscale);
357  if (row > rows)
358  break;
359  source = data + cols*row;
360  dest = &image32[i*256];
361  fracstep = cols*0x10000/256;
362  frac = fracstep >> 1;
363  for (j=0 ; j<256 ; j++)
364  {
365  dest[j] = r_rawpalette[source[frac>>16]];
366  frac += fracstep;
367  }
368  }
369 
370  qglTexImage2D (GL_TEXTURE_2D, 0, gl_tex_solid_format, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, image32);
371  }
372  else
373  {
374  unsigned char *dest;
375 
376  for (i=0 ; i<trows ; i++)
377  {
378  row = (int)(i*hscale);
379  if (row > rows)
380  break;
381  source = data + cols*row;
382  dest = &image8[i*256];
383  fracstep = cols*0x10000/256;
384  frac = fracstep >> 1;
385  for (j=0 ; j<256 ; j++)
386  {
387  dest[j] = source[frac>>16];
388  frac += fracstep;
389  }
390  }
391 
392  qglTexImage2D( GL_TEXTURE_2D,
393  0,
395  256, 256,
396  0,
397  GL_COLOR_INDEX,
398  GL_UNSIGNED_BYTE,
399  image8 );
400  }
401  qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
402  qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
403 
405  qglDisable (GL_ALPHA_TEST);
406 
407  qglBegin (GL_QUADS);
408  qglTexCoord2f (0, 0);
409  qglVertex2f (x, y);
410  qglTexCoord2f (1, 0);
411  qglVertex2f (x+w, y);
412  qglTexCoord2f (1, t);
413  qglVertex2f (x+w, y+h);
414  qglTexCoord2f (0, t);
415  qglVertex2f (x, y+h);
416  qglEnd ();
417 
419  qglEnable (GL_ALPHA_TEST);
420 }

◆ Draw_TileClear()

void Draw_TileClear ( int  x,
int  y,
int  w,
int  h,
char *  pic 
)

Definition at line 220 of file gl_draw.c.

221 {
222  image_t *image;
223 
224  image = Draw_FindPic (pic);
225  if (!image)
226  {
227  ri.Con_Printf (PRINT_ALL, "Can't find pic: %s\n", pic);
228  return;
229  }
230 
232  qglDisable (GL_ALPHA_TEST);
233 
234  GL_Bind (image->texnum);
235  qglBegin (GL_QUADS);
236  qglTexCoord2f (x/64.0, y/64.0);
237  qglVertex2f (x, y);
238  qglTexCoord2f ( (x+w)/64.0, y/64.0);
239  qglVertex2f (x+w, y);
240  qglTexCoord2f ( (x+w)/64.0, (y+h)/64.0);
241  qglVertex2f (x+w, y+h);
242  qglTexCoord2f ( x/64.0, (y+h)/64.0 );
243  qglVertex2f (x, y+h);
244  qglEnd ();
245 
247  qglEnable (GL_ALPHA_TEST);
248 }

◆ Scrap_Upload()

void Scrap_Upload ( void  )

Definition at line 411 of file gl_image.c.

412 {
413  scrap_uploads++;
415  GL_Upload8 (scrap_texels[0], BLOCK_WIDTH, BLOCK_HEIGHT, false, false );
416  scrap_dirty = false;
417 }

Referenced by Draw_Pic(), and Draw_StretchPic().

Variable Documentation

◆ draw_chars

image_t* draw_chars

Definition at line 25 of file gl_draw.c.

Referenced by Draw_Char(), and Draw_InitLocal().

◆ r_rawpalette

unsigned r_rawpalette[256]

Definition at line 1572 of file gl_rmain.c.

Referenced by Draw_StretchRaw().

◆ scrap_dirty

qboolean scrap_dirty

Definition at line 365 of file gl_image.c.

Referenced by Draw_Pic(), Draw_StretchPic(), GL_LoadPic(), and Scrap_Upload().

GL_COLOR_INDEX8_EXT
#define GL_COLOR_INDEX8_EXT
Definition: gl_local.h:34
MAX_QPATH
#define MAX_QPATH
Definition: q_shared.h:80
scrap_uploads
int scrap_uploads
Definition: gl_image.c:409
int
CONST PIXELFORMATDESCRIPTOR int
Definition: qgl_win.c:35
image_s::th
float th
Definition: gl_local.h:96
scrap_texels
byte scrap_texels[MAX_SCRAPS][BLOCK_WIDTH *BLOCK_HEIGHT]
Definition: gl_image.c:364
scrap_dirty
qboolean scrap_dirty
Definition: gl_image.c:365
ri
refimport_t ri
Definition: r_main.c:25
v
GLdouble v
Definition: qgl_win.c:143
refimport_t::Cvar_Get
cvar_t *(* Cvar_Get)(char *name, char *value, int flags)
Definition: ref.h:216
x
GLint GLenum GLint x
Definition: qgl_win.c:116
i
int i
Definition: q_shared.c:305
GL_RENDERER_MCD
#define GL_RENDERER_MCD
Definition: gl_local.h:393
GL_RENDERER_RENDITION
#define GL_RENDERER_RENDITION
Definition: gl_local.h:385
cvar_s
Definition: q_shared.h:324
j
GLint j
Definition: qgl_win.c:150
refimport_t::Con_Printf
void(* Con_Printf)(int print_level, char *str,...)
Definition: ref.h:202
GL_FindImage
image_t * GL_FindImage(char *name, imagetype_t type)
Definition: gl_image.c:1363
PRINT_ALL
#define PRINT_ALL
Definition: qcommon.h:751
it_pic
@ it_pic
Definition: r_local.h:67
image_s::height
int height
Definition: r_local.h:75
viddef_t::width
unsigned width
Definition: vid.h:29
t
GLdouble t
Definition: qgl_win.c:328
image_s::texnum
int texnum
Definition: gl_local.h:95
refimport_t::Sys_Error
void(* Sys_Error)(int err_level, char *str,...)
Definition: ref.h:194
GL_Bind
void GL_Bind(int texnum)
Definition: gl_image.c:137
viddef_t::height
unsigned height
Definition: vid.h:29
cvar_s::value
float value
Definition: q_shared.h:331
GL_Upload8
qboolean GL_Upload8(byte *data, int width, int height, qboolean mipmap, qboolean is_sky)
Definition: gl_image.c:1177
scrap_dirty
qboolean scrap_dirty
Definition: gl_image.c:365
image_s::width
int width
Definition: r_local.h:75
Scrap_Upload
void Scrap_Upload(void)
Definition: gl_image.c:411
image_s::tl
float tl
Definition: gl_local.h:96
name
cvar_t * name
Definition: cl_main.c:79
ERR_FATAL
#define ERR_FATAL
Definition: qcommon.h:743
glconfig_t::renderer
int renderer
Definition: gl_local.h:398
y
GLint y
Definition: qgl_win.c:115
r_rawpalette
unsigned r_rawpalette[256]
Definition: gl_rmain.c:1572
gl_tex_solid_format
int gl_tex_solid_format
Definition: gl_image.c:42
d_8to24table
unsigned d_8to24table[256]
Definition: r_main.c:27
image_s::sl
float sl
Definition: gl_local.h:96
gl_config
glconfig_t gl_config
Definition: gl_rmain.c:41
image_s::has_alpha
qboolean has_alpha
Definition: gl_local.h:98
BLOCK_HEIGHT
#define BLOCK_HEIGHT
Definition: gl_image.c:361
w
GLdouble GLdouble GLdouble w
Definition: qgl_win.c:291
image_s
Definition: r_local.h:71
Com_sprintf
void Com_sprintf(char *dest, int size, char *fmt,...)
Definition: q_shared.c:1223
TEXNUM_SCRAPS
#define TEXNUM_SCRAPS
Definition: gl_local.h:104
BLOCK_WIDTH
#define BLOCK_WIDTH
Definition: gl_image.c:360
Draw_FindPic
image_t * Draw_FindPic(char *name)
Definition: gl_draw.c:97
image_s::sh
float sh
Definition: gl_local.h:96
draw_chars
image_t * draw_chars
Definition: gl_draw.c:25
vid
viddef_t vid
Definition: r_main.c:24