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.
21 // draw.c -- this is the only file outside the refresh that touches the
26 //#define GL_COLOR_INDEX8_EXT 0x80E5
28 cvar_t scr_conalpha = {"scr_conalpha", "1"};
30 byte *draw_chars; // 8*8 graphic characters
33 rtexture_t *char_texture;
40 rtexture_t *conbacktex;
42 //=============================================================================
43 /* Support Routines */
45 typedef struct cachepic_s
49 byte padding[32]; // for appended glpic
52 #define MAX_CACHED_PICS 128
53 cachepic_t menu_cachepics[MAX_CACHED_PICS];
54 int menu_numcachepics;
56 byte menuplyr_pixels[4096];
61 qpic_t *Draw_PicFromWad (char *name)
66 p = W_GetLumpName (name);
67 gl = (glpic_t *)p->data;
69 gl->tex = R_LoadTexture (name, p->width, p->height, p->data, TEXF_ALPHA | TEXF_PRECACHE);
79 qpic_t *Draw_CachePic (char *path)
86 for (pic=menu_cachepics, i=0 ; i<menu_numcachepics ; pic++, i++)
87 if (!strcmp (path, pic->name))
90 if (menu_numcachepics == MAX_CACHED_PICS)
91 Sys_Error ("menu_numcachepics == MAX_CACHED_PICS");
93 strcpy (pic->name, path);
96 // load the pic from disk
98 dat = (qpic_t *)COM_LoadMallocFile (path, false);
100 Sys_Error ("Draw_CachePic: failed to load %s", path);
103 // HACK HACK HACK --- we need to keep the bytes for
104 // the translatable player picture just for the menu
105 // configuration dialog
106 if (!strcmp (path, "gfx/menuplyr.lmp"))
107 memcpy (menuplyr_pixels, dat->data, dat->width*dat->height);
109 pic->pic.width = dat->width;
110 pic->pic.height = dat->height;
112 gl = (glpic_t *)pic->pic.data;
113 gl->tex = loadtextureimage(path, 0, 0, false, false, true);
115 gl->tex = R_LoadTexture (path, dat->width, dat->height, dat->data, TEXF_ALPHA | TEXF_PRECACHE);
127 void gl_draw_start(void)
131 char_texture = loadtextureimage ("conchars", 0, 0, false, false, true);
134 draw_chars = W_GetLumpName ("conchars");
135 for (i=0 ; i<128*128 ; i++)
136 if (draw_chars[i] == 0)
137 draw_chars[i] = 255; // proper transparent color
139 // now turn them into textures
140 char_texture = R_LoadTexture ("charset", 128, 128, draw_chars, TEXF_ALPHA | TEXF_PRECACHE);
143 conbacktex = loadtextureimage("gfx/conback", 0, 0, false, false, true);
145 // get the other pics we need
146 draw_disc = Draw_PicFromWad ("disc");
149 void gl_draw_shutdown(void)
153 void gl_draw_newmap(void)
157 char engineversion[40];
158 int engineversionx, engineversiony;
160 extern void R_Textures_Init();
161 void GL_Draw_Init (void)
164 Cvar_RegisterVariable (&scr_conalpha);
166 Cmd_AddCommand ("loadsky", &LoadSky_f);
168 #if defined(__linux__)
169 sprintf (engineversion, "DarkPlaces Linux GL %.2f build %3i", (float) VERSION, buildnumber);
171 sprintf (engineversion, "DarkPlaces Windows GL %.2f build %3i", (float) VERSION, buildnumber);
173 sprintf (engineversion, "DarkPlaces Unknown GL %.2f build %3i", (float) VERSION, buildnumber);
175 for (i = 0;i < 40 && engineversion[i];i++)
176 engineversion[i] += 0x80; // shift to orange
177 engineversionx = vid.width - strlen(engineversion) * 8 - 8;
178 engineversiony = vid.height - 8;
181 R_RegisterModule("GL_Draw", gl_draw_start, gl_draw_shutdown, gl_draw_newmap);
188 Draws one 8*8 graphics character with 0 being transparent.
189 It can be clipped to the top of the screen to allow the console to be
190 smoothly scrolled off.
193 void Draw_Character (int x, int y, int num)
196 float frow, fcol, size;
204 return; // totally off screen
215 glBindTexture(GL_TEXTURE_2D, R_GetTexture(char_texture));
216 // LordHavoc: NEAREST mode on text if not scaling up
217 if (glwidth <= (int) vid.width)
219 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
220 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
224 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
225 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
229 glColor3f(0.5f,0.5f,0.5f);
231 glColor3f(1.0f,1.0f,1.0f);
233 glTexCoord2f (fcol, frow);
235 glTexCoord2f (fcol + size, frow);
237 glTexCoord2f (fcol + size, frow + size);
238 glVertex2f (x+8, y+8);
239 glTexCoord2f (fcol, frow + size);
243 // LordHavoc: revert to LINEAR mode
244 // if (glwidth < (int) vid.width)
246 // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
247 // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
256 // LordHavoc: sped this up a lot, and added maxlen
257 void Draw_String (int x, int y, char *str, int maxlen)
263 if (y <= -8 || y >= (int) vid.height || x >= (int) vid.width || *str == 0) // completely offscreen or no text to print
266 maxlen = strlen(str);
267 else if (maxlen > (int) strlen(str))
268 maxlen = strlen(str);
269 glBindTexture(GL_TEXTURE_2D, R_GetTexture(char_texture));
271 // LordHavoc: NEAREST mode on text if not scaling up
272 if (glwidth <= (int) vid.width)
274 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
275 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
279 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
280 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
284 glColor3f(0.5f,0.5f,0.5f);
286 glColor3f(1.0f,1.0f,1.0f);
288 while (maxlen-- && x < (int) vid.width) // stop rendering when out of characters or room
290 if ((num = *str++) != 32) // skip spaces
292 frow = (float) ((int) num >> 4)*0.0625;
293 fcol = (float) ((int) num & 15)*0.0625;
294 glTexCoord2f (fcol , frow );glVertex2f (x, y);
295 glTexCoord2f (fcol + 0.0625, frow );glVertex2f (x+8, y);
296 glTexCoord2f (fcol + 0.0625, frow + 0.0625);glVertex2f (x+8, y+8);
297 glTexCoord2f (fcol , frow + 0.0625);glVertex2f (x, y+8);
303 // LordHavoc: revert to LINEAR mode
304 // if (glwidth < (int) vid.width)
306 // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
307 // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
311 void Draw_GenericPic (rtexture_t *tex, float red, float green, float blue, float alpha, int x, int y, int width, int height)
316 glColor4f(red * 0.5f, green * 0.5f, blue * 0.5f, alpha);
318 glColor4f(red, green, blue, alpha);
319 glBindTexture(GL_TEXTURE_2D, R_GetTexture(tex));
321 glTexCoord2f (0, 0);glVertex2f (x, y);
322 glTexCoord2f (1, 0);glVertex2f (x+width, y);
323 glTexCoord2f (1, 1);glVertex2f (x+width, y+height);
324 glTexCoord2f (0, 1);glVertex2f (x, y+height);
333 void Draw_AlphaPic (int x, int y, qpic_t *pic, float alpha)
335 Draw_GenericPic(((glpic_t *)pic->data)->tex, 1,1,1,alpha, x,y,pic->width, pic->height);
344 void Draw_Pic (int x, int y, qpic_t *pic)
346 Draw_GenericPic(((glpic_t *)pic->data)->tex, 1,1,1,1, x,y,pic->width, pic->height);
354 Only used for the player color selection menu
357 void Draw_PicTranslate (int x, int y, qpic_t *pic, byte *translation)
360 byte *trans, *src, *dest;
363 c = pic->width * pic->height;
364 src = menuplyr_pixels;
365 dest = trans = qmalloc(c);
366 for (i = 0;i < c;i++)
367 *dest++ = translation[*src++];
369 rt = R_LoadTexture ("translatedplayerpic", pic->width, pic->height, trans, TEXF_ALPHA | TEXF_PRECACHE);
374 Draw_GenericPic (rt, 1,1,1,1, x, y, pic->width, pic->height);
380 Draw_ConsoleBackground
384 void Draw_ConsoleBackground (int lines)
386 Draw_GenericPic (conbacktex, 1,1,1,scr_conalpha.value*lines/vid.height, 0, lines - vid.height, vid.width, vid.height);
387 // LordHavoc: draw version
388 Draw_String(engineversionx, lines - vid.height + engineversiony, engineversion, 9999);
395 Fills a box of pixels with a single color
398 void Draw_Fill (int x, int y, int w, int h, int c)
402 glDisable (GL_TEXTURE_2D);
405 byte *tempcolor = (byte *)&d_8to24table[c];
406 glColor4ub ((byte) (tempcolor[0] >> 1), (byte) (tempcolor[1] >> 1), (byte) (tempcolor[2] >> 1), tempcolor[3]);
409 glColor4ubv ((byte *)&d_8to24table[c]);
415 glVertex2f (x+w, y+h);
420 glEnable (GL_TEXTURE_2D);
422 //=============================================================================
424 //=============================================================================
430 Setup as if the screen was 320*200
437 glViewport (glx, gly, glwidth, glheight);
439 glMatrixMode(GL_PROJECTION);
441 glOrtho (0, vid.width, vid.height, 0, -99999, 99999);
443 glMatrixMode(GL_MODELVIEW);
446 glDisable (GL_DEPTH_TEST);
447 glDisable (GL_CULL_FACE);
449 glDisable (GL_ALPHA_TEST);
450 glEnable(GL_TEXTURE_2D);
452 // LordHavoc: added this
453 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
454 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
459 // LordHavoc: SHOWLMP stuff
460 #define SHOWLMP_MAXLABELS 256
461 typedef struct showlmp_s
470 showlmp_t showlmp[SHOWLMP_MAXLABELS];
472 void SHOWLMP_decodehide(void)
476 lmplabel = MSG_ReadString();
477 for (i = 0;i < SHOWLMP_MAXLABELS;i++)
478 if (showlmp[i].isactive && strcmp(showlmp[i].label, lmplabel) == 0)
480 showlmp[i].isactive = false;
485 void SHOWLMP_decodeshow(void)
488 byte lmplabel[256], picname[256];
490 strcpy(lmplabel,MSG_ReadString());
491 strcpy(picname, MSG_ReadString());
492 if (nehahra) // LordHavoc: nasty old legacy junk
503 for (i = 0;i < SHOWLMP_MAXLABELS;i++)
504 if (showlmp[i].isactive)
506 if (strcmp(showlmp[i].label, lmplabel) == 0)
509 break; // drop out to replace it
512 else if (k < 0) // find first empty one to replace
515 return; // none found to replace
516 // change existing one
517 showlmp[k].isactive = true;
518 strcpy(showlmp[k].label, lmplabel);
519 strcpy(showlmp[k].pic, picname);
524 void SHOWLMP_drawall(void)
527 for (i = 0;i < SHOWLMP_MAXLABELS;i++)
528 if (showlmp[i].isactive)
529 Draw_Pic(showlmp[i].x, showlmp[i].y, Draw_CachePic(showlmp[i].pic));
532 void SHOWLMP_clear(void)
535 for (i = 0;i < SHOWLMP_MAXLABELS;i++)
536 showlmp[i].isactive = false;