icculus quake2 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  row = num>>4;
70  col = num&15;
71 
72  frow = row*0.0625;
73  fcol = col*0.0625;
74  size = 0.0625;
75 
77 
78  qglBegin (GL_QUADS);
79  qglTexCoord2f (fcol, frow);
80  qglVertex2f (x, y);
81  qglTexCoord2f (fcol + size, frow);
82  qglVertex2f (x+8, y);
83  qglTexCoord2f (fcol + size, frow + size);
84  qglVertex2f (x+8, y+8);
85  qglTexCoord2f (fcol, frow + size);
86  qglVertex2f (x, y+8);
87  qglEnd ();
88 }

Referenced by GetRefAPI().

◆ Draw_FadeScreen()

void Draw_FadeScreen ( void  )

Definition at line 290 of file gl_draw.c.

291 {
292  qglEnable (GL_BLEND);
293  qglDisable (GL_TEXTURE_2D);
294  qglColor4f (0, 0, 0, 0.8);
295  qglBegin (GL_QUADS);
296 
297  qglVertex2f (0,0);
298  qglVertex2f (vid.width, 0);
299  qglVertex2f (vid.width, vid.height);
300  qglVertex2f (0, vid.height);
301 
302  qglEnd ();
303  qglColor4f (1,1,1,1);
304  qglEnable (GL_TEXTURE_2D);
305  qglDisable (GL_BLEND);
306 }

Referenced by GetRefAPI().

◆ Draw_Fill()

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

Definition at line 252 of file gl_draw.c.

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

Referenced by GetRefAPI().

◆ Draw_FindPic()

image_t* Draw_FindPic ( char *  name)

Definition at line 95 of file gl_draw.c.

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

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

◆ Draw_GetPicSize()

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

Definition at line 116 of file gl_draw.c.

117 {
118  image_t *gl;
119 
120  gl = Draw_FindPic (pic);
121  if (!gl)
122  {
123  *w = *h = -1;
124  return;
125  }
126  *w = gl->width;
127  *h = gl->height;
128 }

◆ 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 174 of file gl_draw.c.

175 {
176  image_t *gl;
177 
178  gl = Draw_FindPic (pic);
179  if (!gl)
180  {
181  ri.Con_Printf (PRINT_ALL, "Can't find pic: %s\n", pic);
182  return;
183  }
184  if (scrap_dirty)
185  Scrap_Upload ();
186 
188  qglDisable (GL_ALPHA_TEST);
189 
190  GL_Bind (gl->texnum);
191  qglBegin (GL_QUADS);
192  qglTexCoord2f (gl->sl, gl->tl);
193  qglVertex2f (x, y);
194  qglTexCoord2f (gl->sh, gl->tl);
195  qglVertex2f (x+gl->width, y);
196  qglTexCoord2f (gl->sh, gl->th);
197  qglVertex2f (x+gl->width, y+gl->height);
198  qglTexCoord2f (gl->sl, gl->th);
199  qglVertex2f (x, y+gl->height);
200  qglEnd ();
201 
203  qglEnable (GL_ALPHA_TEST);
204 }

Referenced by GetRefAPI().

◆ Draw_StretchPic()

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

Definition at line 135 of file gl_draw.c.

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

◆ Draw_StretchRaw()

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

Definition at line 319 of file gl_draw.c.

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

◆ Draw_TileClear()

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

Definition at line 214 of file gl_draw.c.

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

Referenced by GetRefAPI().

◆ Scrap_Upload()

void Scrap_Upload ( void  )

Definition at line 410 of file gl_image.c.

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

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 1573 of file gl_rmain.c.

Referenced by Draw_StretchRaw(), and R_SetPalette().

◆ scrap_dirty

qboolean scrap_dirty

Definition at line 364 of file gl_image.c.

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

MAX_QPATH
#define MAX_QPATH
Definition: q_shared.h:73
scrap_uploads
int scrap_uploads
Definition: gl_image.c:408
int
CONST PIXELFORMATDESCRIPTOR int
Definition: qgl_win.c:35
image_s::th
float th
Definition: gl_local.h:103
scrap_texels
byte scrap_texels[MAX_SCRAPS][BLOCK_WIDTH *BLOCK_HEIGHT]
Definition: gl_image.c:363
scrap_dirty
qboolean scrap_dirty
Definition: gl_image.c:364
ri
refimport_t ri
Definition: r_main.c:25
v
GLdouble v
Definition: qgl_win.c:143
x
GLint GLenum GLint x
Definition: qgl_win.c:116
viddef_t::width
int width
Definition: vid.h:29
i
int i
Definition: q_shared.c:305
viddef_t::height
int height
Definition: vid.h:29
GL_RENDERER_MCD
#define GL_RENDERER_MCD
Definition: gl_local.h:401
GL_RENDERER_RENDITION
#define GL_RENDERER_RENDITION
Definition: gl_local.h:393
j
GLint j
Definition: qgl_win.c:150
refimport_t::Con_Printf
void(* Con_Printf)(int print_level, char *str,...)
Definition: ref.h:228
GL_FindImage
image_t * GL_FindImage(char *name, imagetype_t type)
Definition: gl_image.c:1393
PRINT_ALL
#define PRINT_ALL
Definition: qcommon.h:743
it_pic
@ it_pic
Definition: r_local.h:61
image_s::height
int height
Definition: r_local.h:69
t
GLdouble t
Definition: qgl_win.c:328
image_s::texnum
int texnum
Definition: gl_local.h:102
refimport_t::Sys_Error
void(* Sys_Error)(int err_level, char *str,...)
Definition: ref.h:220
GL_Bind
void GL_Bind(int texnum)
Definition: gl_image.c:136
GL_Upload8
qboolean GL_Upload8(byte *data, int width, int height, qboolean mipmap, qboolean is_sky)
Definition: gl_image.c:1185
scrap_dirty
qboolean scrap_dirty
Definition: gl_image.c:364
image_s::width
int width
Definition: r_local.h:69
Scrap_Upload
void Scrap_Upload(void)
Definition: gl_image.c:410
image_s::tl
float tl
Definition: gl_local.h:103
name
cvar_t * name
Definition: cl_main.c:94
ERR_FATAL
#define ERR_FATAL
Definition: qcommon.h:735
glconfig_t::renderer
int renderer
Definition: gl_local.h:406
y
GLint y
Definition: qgl_win.c:115
r_rawpalette
unsigned r_rawpalette[256]
Definition: gl_rmain.c:1573
gl_tex_solid_format
int gl_tex_solid_format
Definition: gl_image.c:41
d_8to24table
unsigned d_8to24table[256]
Definition: r_main.c:27
image_s::sl
float sl
Definition: gl_local.h:103
gl_config
glconfig_t gl_config
Definition: gl_rmain.c:35
image_s::has_alpha
qboolean has_alpha
Definition: gl_local.h:105
BLOCK_HEIGHT
#define BLOCK_HEIGHT
Definition: gl_image.c:360
w
GLdouble GLdouble GLdouble w
Definition: qgl_win.c:291
image_s
Definition: r_local.h:65
Com_sprintf
void Com_sprintf(char *dest, int size, char *fmt,...)
Definition: q_shared.c:1236
TEXNUM_SCRAPS
#define TEXNUM_SCRAPS
Definition: gl_local.h:111
BLOCK_WIDTH
#define BLOCK_WIDTH
Definition: gl_image.c:359
Draw_FindPic
image_t * Draw_FindPic(char *name)
Definition: gl_draw.c:95
image_s::sh
float sh
Definition: gl_local.h:103
draw_chars
image_t * draw_chars
Definition: gl_draw.c:25
vid
viddef_t vid
Definition: r_main.c:24