2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
23 cvar_t scr_conalpha = {CVAR_SAVE, "scr_conalpha", "1"};
25 static rtexture_t *char_texture;
27 //=============================================================================
28 /* Support Routines */
30 #define MAX_CACHED_PICS 256
31 #define CACHEPICHASHSIZE 256
32 static cachepic_t *cachepichash[CACHEPICHASHSIZE];
33 static cachepic_t cachepics[MAX_CACHED_PICS];
34 static int numcachepics;
36 static rtexturepool_t *drawtexturepool;
38 static qbyte pointerimage[256] =
58 static rtexture_t *draw_generatemousepointer(void)
62 for (i = 0;i < 256;i++)
64 if (pointerimage[i] == '.')
73 buffer[i][0] = (pointerimage[i] - '0') * 16;
74 buffer[i][1] = (pointerimage[i] - '0') * 16;
75 buffer[i][2] = (pointerimage[i] - '0') * 16;
79 return R_LoadTexture(drawtexturepool, "mousepointer", 16, 16, &buffer[0][0], TEXTYPE_RGBA, TEXF_ALPHA | TEXF_PRECACHE);
82 // must match NUMCROSSHAIRS in r_crosshairs.c
83 #define NUMCROSSHAIRS 5
85 static qbyte *crosshairtexdata[NUMCROSSHAIRS] =
173 static rtexture_t *draw_generatecrosshair(int num)
177 qbyte data[16*16][4];
178 in = crosshairtexdata[num];
179 for (i = 0;i < 16*16;i++)
193 data[i][3] = (qbyte) ((int) (in[i] - '0') * 255 / 7);
196 return R_LoadTexture(drawtexturepool, va("crosshair%i", num), 16, 16, &data[0][0], TEXTYPE_RGBA, TEXF_ALPHA | TEXF_PRECACHE);
204 // FIXME: move this to client somehow
205 cachepic_t *Draw_CachePic (char *path)
211 crc = CRC_Block(path, strlen(path));
212 hashkey = ((crc >> 8) ^ crc) % CACHEPICHASHSIZE;
213 for (pic = cachepichash[hashkey];pic;pic = pic->chain)
214 if (!strcmp (path, pic->name))
217 if (numcachepics == MAX_CACHED_PICS)
218 Sys_Error ("numcachepics == MAX_CACHED_PICS");
219 pic = cachepics + (numcachepics++);
220 strcpy (pic->name, path);
222 pic->chain = cachepichash[hashkey];
223 cachepichash[hashkey] = pic;
225 // load the pic from disk
226 pic->tex = loadtextureimage(drawtexturepool, path, 0, 0, false, false, true);
227 if (pic->tex == NULL && (p = W_GetLumpName (path)))
229 if (!strcmp(path, "conchars"))
232 // conchars is a raw image and with the wrong transparent color
234 for (i = 0;i < 128 * 128;i++)
237 pic->tex = R_LoadTexture (drawtexturepool, path, 128, 128, pix, TEXTYPE_QPALETTE, TEXF_ALPHA | TEXF_PRECACHE);
240 pic->tex = R_LoadTexture (drawtexturepool, path, p->width, p->height, p->data, TEXTYPE_QPALETTE, TEXF_ALPHA | TEXF_PRECACHE);
242 if (pic->tex == NULL && !strcmp(path, "ui/mousepointer.tga"))
243 pic->tex = draw_generatemousepointer();
244 if (pic->tex == NULL && !strcmp(path, "gfx/crosshair1.tga"))
245 pic->tex = draw_generatecrosshair(0);
246 if (pic->tex == NULL && !strcmp(path, "gfx/crosshair2.tga"))
247 pic->tex = draw_generatecrosshair(1);
248 if (pic->tex == NULL && !strcmp(path, "gfx/crosshair3.tga"))
249 pic->tex = draw_generatecrosshair(2);
250 if (pic->tex == NULL && !strcmp(path, "gfx/crosshair4.tga"))
251 pic->tex = draw_generatecrosshair(3);
252 if (pic->tex == NULL && !strcmp(path, "gfx/crosshair5.tga"))
253 pic->tex = draw_generatecrosshair(4);
254 if (pic->tex == NULL)
255 Sys_Error ("Draw_CachePic: failed to load %s", path);
257 pic->width = R_TextureWidth(pic->tex);
258 pic->height = R_TextureHeight(pic->tex);
267 static void gl_draw_start(void)
269 drawtexturepool = R_AllocTexturePool();
272 memset(cachepichash, 0, sizeof(cachepichash));
274 char_texture = Draw_CachePic("conchars")->tex;
277 static void gl_draw_shutdown(void)
279 R_FreeTexturePool(&drawtexturepool);
282 memset(cachepichash, 0, sizeof(cachepichash));
285 static void gl_draw_newmap(void)
289 void GL_Draw_Init (void)
291 Cvar_RegisterVariable (&scr_conalpha);
294 memset(cachepichash, 0, sizeof(cachepichash));
296 R_RegisterModule("GL_Draw", gl_draw_start, gl_draw_shutdown, gl_draw_newmap);
299 void R_DrawQueue(void)
301 int pos, num, chartexnum, overbright;
302 float x, y, w, h, s, t, u, v;
305 char *str, *currentpic;
306 int batch, batchcount, additive;
309 if (!r_render.integer)
312 qglViewport(vid.realx, vid.realy, vid.realwidth, vid.realheight);
314 qglMatrixMode(GL_PROJECTION);
316 qglOrtho(0, vid.conwidth, vid.conheight, 0, -99999, 99999);
318 qglMatrixMode(GL_MODELVIEW);
321 qglDisable(GL_DEPTH_TEST);
322 qglDisable(GL_CULL_FACE);
324 qglEnable(GL_TEXTURE_2D);
325 qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
327 chartexnum = R_GetTexture(char_texture);
330 qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
333 qglBindTexture(GL_TEXTURE_2D, 0);
335 qglColor4ub(0,0,0,0);
337 overbright = v_overbrightbits.integer;
340 for (pos = 0;pos < r_refdef.drawqueuesize;pos += ((drawqueue_t *)(r_refdef.drawqueue + pos))->size)
342 dq = (drawqueue_t *)(r_refdef.drawqueue + pos);
343 if (dq->flags & DRAWFLAG_ADDITIVE)
353 qglBlendFunc(GL_SRC_ALPHA, GL_ONE);
366 qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
369 if (color != dq->color)
372 qglColor4ub((qbyte)(((color >> 24) & 0xFF) >> overbright), (qbyte)(((color >> 16) & 0xFF) >> overbright), (qbyte)(((color >> 8) & 0xFF) >> overbright), (qbyte)(color & 0xFF));
374 if (batch && batchcount > 128)
386 str = (char *)(dq + 1);
389 if (strcmp(str, currentpic))
397 pic = Draw_CachePic(str);
398 qglBindTexture(GL_TEXTURE_2D, R_GetTexture(pic->tex));
407 qglBegin(GL_TRIANGLES);
410 qglTexCoord2f (0, 0);qglVertex2f (x , y );
411 qglTexCoord2f (1, 0);qglVertex2f (x+w, y );
412 qglTexCoord2f (1, 1);qglVertex2f (x+w, y+h);
413 qglTexCoord2f (0, 0);qglVertex2f (x , y );
414 qglTexCoord2f (1, 1);qglVertex2f (x+w, y+h);
415 qglTexCoord2f (0, 1);qglVertex2f (x , y+h);
428 qglBindTexture(GL_TEXTURE_2D, 0);
433 qglBegin(GL_TRIANGLES);
436 qglTexCoord2f (0, 0);qglVertex2f (x , y );
437 qglTexCoord2f (1, 0);qglVertex2f (x+w, y );
438 qglTexCoord2f (1, 1);qglVertex2f (x+w, y+h);
439 qglTexCoord2f (0, 0);qglVertex2f (x , y );
440 qglTexCoord2f (1, 1);qglVertex2f (x+w, y+h);
441 qglTexCoord2f (0, 1);qglVertex2f (x , y+h);
445 case DRAWQUEUE_STRING:
446 str = (char *)(dq + 1);
447 if (strcmp("conchars", currentpic))
454 currentpic = "conchars";
455 qglBindTexture(GL_TEXTURE_2D, chartexnum);
460 qglBegin(GL_TRIANGLES);
463 while ((num = *str++) && x < vid.conwidth)
467 s = (num & 15)*0.0625f + (0.5f / 256.0f);
468 t = (num >> 4)*0.0625f + (0.5f / 256.0f);
469 u = 0.0625f - (1.0f / 256.0f);
470 v = 0.0625f - (1.0f / 256.0f);
471 qglTexCoord2f (s , t );qglVertex2f (x , y );
472 qglTexCoord2f (s+u, t );qglVertex2f (x+w, y );
473 qglTexCoord2f (s+u, t+v);qglVertex2f (x+w, y+h);
474 qglTexCoord2f (s , t );qglVertex2f (x , y );
475 qglTexCoord2f (s+u, t+v);qglVertex2f (x+w, y+h);
476 qglTexCoord2f (s , t+v);qglVertex2f (x , y+h);
488 if (!v_hwgamma.integer)
490 qglDisable(GL_TEXTURE_2D);
492 t = v_contrast.value * (float) (1 << v_overbrightbits.integer);
495 qglBlendFunc (GL_DST_COLOR, GL_ONE);
497 qglBegin (GL_TRIANGLES);
500 num = (int) ((t - 1.0f) * 255.0f);
503 qglColor4ub ((qbyte) num, (qbyte) num, (qbyte) num, 255);
504 qglVertex2f (-5000, -5000);
505 qglVertex2f (10000, -5000);
506 qglVertex2f (-5000, 10000);
514 qglBlendFunc(GL_ZERO, GL_SRC_COLOR);
516 qglBegin(GL_TRIANGLES);
517 num = (int) (t * 255.0f);
518 qglColor4ub ((qbyte) num, (qbyte) num, (qbyte) num, 255);
519 qglVertex2f (-5000, -5000);
520 qglVertex2f (10000, -5000);
521 qglVertex2f (-5000, 10000);
525 if (v_brightness.value >= 0.01f)
527 qglBlendFunc (GL_ONE, GL_ONE);
529 num = (int) (v_brightness.value * 255.0f);
530 qglColor4ub ((qbyte) num, (qbyte) num, (qbyte) num, 255);
532 qglBegin (GL_TRIANGLES);
533 qglVertex2f (-5000, -5000);
534 qglVertex2f (10000, -5000);
535 qglVertex2f (-5000, 10000);
539 qglEnable(GL_TEXTURE_2D);
543 qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
545 qglEnable (GL_CULL_FACE);
547 qglEnable (GL_DEPTH_TEST);
549 qglDisable (GL_BLEND);
551 qglColor4ub (255, 255, 255, 255);