/* Copyright (C) 1996-1997 Id Software, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "quakedef.h" float scr_centertime_start; // for slow victory printing float scr_centertime_off; int char_texture; int scr_center_lines; int scr_erase_lines; int scr_erase_center; int font_initialised = true; cvar_t scr_centertime = {"scr_centertime", "2"}; cvar_t scr_printspeed = {"scr_printspeed", "8"}; qboolean scr_drawdialog; char scr_centerstring[1024]; char *scr_notifystring; int char_texture; /* ========= Font_Init ========= */ void Font_Init(void) { byte *draw_chars;// 8*8 graphic characters int i; Cvar_RegisterVariable (&scr_centertime); Cvar_RegisterVariable (&scr_printspeed); char_texture = loadtextureimage ("gfx/wad/conchars", false, false); if (!char_texture) { draw_chars = W_GetLumpName ("conchars"); for (i=0 ; i<256*64 ; i++) if (draw_chars[i] == 0) draw_chars[i] = 255; char_texture = GL_LoadTexture ("charset", 128, 128, draw_chars, false, true, 1); } } /* ============== Draw_Character ============== */ void Draw_Character (int x, int y, int num) { int row, col; float frow, fcol; // // Don't print spaces // if (num == 32) return; // // Return if we go offscreen // if (y <= -8) return; // // 255 chars in one charset // num &= 255; row = num>>4; col = num&15; // // Split up in 8X8 pictures // frow = row*0.0625; fcol = col*0.0625; // // Draw the characters // glBindTexture (GL_TEXTURE_2D, char_texture); glBegin (GL_QUADS); glTexCoord2f (fcol, frow); glVertex2f (x, y); glTexCoord2f (fcol + 0.0625, frow); glVertex2f (x + 8, y); glTexCoord2f (fcol + 0.0625, frow + 0.0625); glVertex2f (x + 8, y + 8); glTexCoord2f (fcol, frow + 0.0625); glVertex2f (x, y + 8); glEnd (); } /* ================ Draw_String ================ */ void Draw_Alt_String (int x, int y, char *str, int maxlen) { float r, g, b; int len; int num; int row, col; float frow, fcol; // // Return if we go offscreen // if (y <= -8) return; len = (maxlen) ? maxlen : strlen(str); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBindTexture (GL_TEXTURE_2D, char_texture); glBegin (GL_QUADS); while (*str && len) { if (*str == '&') { ++str; len--; if (!*str) { return; } switch(*str) { case 'f': { ++str; len--; if(!*str) { return; } r = (float)(*str - '0') * 0.11111111; ++str; len--; if(!*str) { return; } g = (float)(*str - '0') * 0.11111111; ++str; len--; if(!*str) { return; } b = (float)(*str - '0') * 0.11111111; ++str; len--; if(!*str) { return; } ++str; len--; if(!*str) { return; } ++str; len--; if(!*str) { return; } glColor3f(r,g,b); break; } case 'r': { glColor3f(1,1,1); ++str; len--; if(!*str) { return; } ++str; len--; if(!*str) { return; } } default: { --str; len++; } } } if (*str != 32) { // // 255 chars in one charset // num = (int)(*str|128); num &= 255; row = num>>4; col = num&15; // // Split up in 8X8 pictures // frow = row*0.0625; fcol = col*0.0625; // // Draw the characters // glTexCoord2f (fcol, frow); glVertex2f (x, y); glTexCoord2f (fcol + 0.0625, frow); glVertex2f (x + 8, y); glTexCoord2f (fcol + 0.0625, frow + 0.0625); glVertex2f (x + 8, y + 8); glTexCoord2f (fcol, frow + 0.0625); glVertex2f (x, y + 8); } ++str; len--; x += 8; if (x > (signed)vid.width - 16) y += 8; } glEnd (); glColor3f(1,1,1); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); } /* ================ Draw_String ================ */ void Draw_String (int x, int y, char *str, int maxlen) { float r, g, b; int len; int num; int row, col; float frow, fcol; // // Return if we go offscreen // if (y <= -8) return; len = (maxlen) ? maxlen : strlen(str); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBindTexture (GL_TEXTURE_2D, char_texture); glBegin (GL_QUADS); while (*str && len) { if (*str == '&') { ++str; len--; if (!*str) { return; } switch(*str) { case 'f': { ++str; len--; if(!*str) { return; } r = (float)(*str - '0') * 0.11111111; ++str; len--; if(!*str) { return; } g = (float)(*str - '0') * 0.11111111; ++str; len--; if(!*str) { return; } b = (float)(*str - '0') * 0.11111111; ++str; len--; if(!*str) { return; } ++str; len--; if(!*str) { return; } ++str; len--; if(!*str) { return; } glColor3f(r,g,b); break; } case 'r': { glColor3f(1,1,1); ++str; len--; if(!*str) { return; } ++str; len--; if(!*str) { return; } } default: { --str; len++; } } } if (*str != 32) { // // 255 chars in one charset // num = (int)*str; num &= 255; row = num>>4; col = num&15; // // Split up in 8X8 pictures // frow = row*0.0625; fcol = col*0.0625; // // Draw the characters // glTexCoord2f (fcol, frow); glVertex2f (x, y); glTexCoord2f (fcol + 0.0625, frow); glVertex2f (x + 8, y); glTexCoord2f (fcol + 0.0625, frow + 0.0625); glVertex2f (x + 8, y + 8); glTexCoord2f (fcol, frow + 0.0625); glVertex2f (x, y + 8); } ++str; len--; x += 8; if (x > (signed)vid.width - 16) y += 8; } glEnd (); glColor3f(1,1,1); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); } /* =============================================================================== CENTER PRINTING =============================================================================== */ /* ============== CPrintf prints a font to centered to the screen, is removed after it is stopped being called ============== */ void CPrintf(char *str) { int x,y,l,j; int font = 0; y = vid.height*0.35; do { // scan the width of the line for (l=0 ; l<40 ; l++) { if (str[l] == '\n' || !str[l]) break; } x = (vid.width - l*20)/2; for (j=0 ; j scr_erase_lines) scr_erase_lines = scr_center_lines; scr_centertime_off -= host_frametime; if (scr_centertime_off <= 0 && !cl.intermission) return; if (key_dest != key_game) return; SCR_DrawCenterString (); } void SCR_DrawNotifyString (void) { char *start; int l; int x, y; start = scr_notifystring; y = vid.height*0.35; do { // scan the width of the line for (l=0 ; l<40 ; l++) if (start[l] == '\n' || !start[l]) break; x = (vid.width - l*8)/2; // for (j=0 ; j