/* * Copyright(c) 1997-2001 Id Software, Inc. * Copyright(c) 2002 The Quakeforge Project. * Copyright(c) 2006 Quetoo. * * 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 "video.h" image_t *draw_chars; extern qboolean scrap_dirty; void Scrap_Upload(void); /* Draw_InitLocal */ void Draw_InitLocal(void){ // load console characters (don't bilerp characters) draw_chars = GL_FindImage("pics/conchars.tga", it_pic); if(!draw_chars) // tga failed, revert to default draw_chars = GL_FindImage("pics/conchars.pcx", it_pic); GL_Bind(draw_chars->texnum); qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); } /* Draw_Char Draws one graphics character with 0 being transparent. It can be clipped to the top of the screen to allow the console to be smoothly scrolled off. */ void Draw_Char(int x, int y, int num){ int row, col; float frow, fcol, size; if(y <= -8) return; // totally off screen num &= 255; if((num & 127) == 32) return; // space row = num >> 4; col = num & 15; frow = row * 0.0625; fcol = col * 0.0625; size = 0.0625; GL_Bind(draw_chars->texnum); qglBegin(GL_QUADS); qglTexCoord2f(fcol, frow); qglVertex2f(x, y); qglTexCoord2f(fcol + size, frow); qglVertex2f(x + 8, y); qglTexCoord2f(fcol + size, frow + size); qglVertex2f(x + 8, y + 8); qglTexCoord2f(fcol, frow + size); qglVertex2f(x, y + 8); qglEnd(); } /* Draw_FindPic */ image_t *Draw_FindPic(char *name){ image_t *gl; char fullname[MAX_QPATH]; if(name[0] != '/' && name[0] != '\\'){ Com_sprintf(fullname, sizeof(fullname), "pics/%s.tga", name); gl = GL_FindImage(fullname, it_pic); if(!gl){ // tga failed, revert to pcx Com_sprintf(fullname, sizeof(fullname), "pics/%s.pcx", name); gl = GL_FindImage(fullname, it_pic); } } else gl = GL_FindImage(name + 1, it_pic); return gl; } /* Draw_GetPicSize */ void Draw_GetPicSize(int *w, int *h, char *pic){ image_t *gl; gl = Draw_FindPic(pic); if(!gl){ *w = *h = -1; return; } *w = gl->width; *h = gl->height; } /* Draw_Pic */ void Draw_Pic(int x, int y, char *pic){ image_t *gl; gl = Draw_FindPic(pic); if(!gl){ Com_Printf( "Can't find pic: %s\n", pic); return; } if(scrap_dirty) Scrap_Upload(); GL_Bind(gl->texnum); qglBegin(GL_QUADS); qglTexCoord2f(gl->sl, gl->tl); qglVertex2f(x, y); qglTexCoord2f(gl->sh, gl->tl); qglVertex2f(x + gl->width, y); qglTexCoord2f(gl->sh, gl->th); qglVertex2f(x + gl->width, y + gl->height); qglTexCoord2f(gl->sl, gl->th); qglVertex2f(x, y + gl->height); qglEnd(); } /* Draw_Fill Fills a box of pixels with a single color */ void Draw_Fill(int x, int y, int w, int h, int c){ union { unsigned c; byte v[4]; } color; if((unsigned)c > 255) Com_Error(ERR_DROP, "Draw_Fill: bad color"); qglDisable(GL_TEXTURE_2D); color.c = d_8to24table[c]; qglColor3ubv(color.v); qglBegin(GL_QUADS); qglVertex2f(x, y); qglVertex2f(x + w, y); qglVertex2f(x + w, y + h); qglVertex2f(x, y + h); qglEnd(); qglColor3ubv(color_white); qglEnable(GL_TEXTURE_2D); }