draw.c
来自「quake1 dos源代码最新版本」· C语言 代码 · 共 958 行 · 第 1/2 页
C
958 行
}
}
else
{ // unwound
for (v=0 ; v<pic->height ; v++)
{
for (u=0 ; u<pic->width ; u+=8)
{
if ( (tbyte=source[u]) != TRANSPARENT_COLOR)
dest[u] = translation[tbyte];
if ( (tbyte=source[u+1]) != TRANSPARENT_COLOR)
dest[u+1] = translation[tbyte];
if ( (tbyte=source[u+2]) != TRANSPARENT_COLOR)
dest[u+2] = translation[tbyte];
if ( (tbyte=source[u+3]) != TRANSPARENT_COLOR)
dest[u+3] = translation[tbyte];
if ( (tbyte=source[u+4]) != TRANSPARENT_COLOR)
dest[u+4] = translation[tbyte];
if ( (tbyte=source[u+5]) != TRANSPARENT_COLOR)
dest[u+5] = translation[tbyte];
if ( (tbyte=source[u+6]) != TRANSPARENT_COLOR)
dest[u+6] = translation[tbyte];
if ( (tbyte=source[u+7]) != TRANSPARENT_COLOR)
dest[u+7] = translation[tbyte];
}
dest += vid.rowbytes;
source += pic->width;
}
}
}
else
{
// FIXME: pretranslate at load time?
pusdest = (unsigned short *)vid.buffer + y * (vid.rowbytes >> 1) + x;
for (v=0 ; v<pic->height ; v++)
{
for (u=0 ; u<pic->width ; u++)
{
tbyte = source[u];
if (tbyte != TRANSPARENT_COLOR)
{
pusdest[u] = d_8to16table[tbyte];
}
}
pusdest += vid.rowbytes >> 1;
source += pic->width;
}
}
}
void Draw_CharToConback (int num, byte *dest)
{
int row, col;
byte *source;
int drawline;
int x;
row = num>>4;
col = num&15;
source = draw_chars + (row<<10) + (col<<3);
drawline = 8;
while (drawline--)
{
for (x=0 ; x<8 ; x++)
if (source[x])
dest[x] = 0x60 + source[x];
source += 128;
dest += 320;
}
}
/*
================
Draw_ConsoleBackground
================
*/
void Draw_ConsoleBackground (int lines)
{
int x, y, v;
byte *src, *dest;
unsigned short *pusdest;
int f, fstep;
qpic_t *conback;
char ver[100];
conback = Draw_CachePic ("gfx/conback.lmp");
// hack the version number directly into the pic
#ifdef _WIN32
sprintf (ver, "(%s, WinQuake) %4.2f", QIP_VERSION, (float)VERSION); // 2001-10-25 QIP version in the console background by Maddes
// dest = conback->data + 320*186 + 320 - 11 - 8*strlen(ver); // 2001-10-25 Version printing fix by Maddes
#elif defined(X11)
sprintf (ver, "(%s, X11 Quake %2.2f) %4.2f", QIP_VERSION, (float)X11_VERSION, (float)VERSION); // 2001-10-25 QIP version in the console background by Maddes
// dest = conback->data + 320*186 + 320 - 11 - 8*strlen(ver); // 2001-10-25 Version printing fix by Maddes
#elif defined(__linux__)
sprintf (ver, "(%s, Linux Quake %2.2f) %4.2f", QIP_VERSION, (float)LINUX_VERSION, (float)VERSION); // 2001-10-25 QIP version in the console background by Maddes
// dest = conback->data + 320*186 + 320 - 11 - 8*strlen(ver); // 2001-10-25 Version printing fix by Maddes
#else
sprintf (ver, "(%s) %4.2f", QIP_VERSION, VERSION); // 2001-10-25 QIP version in the console background by Maddes
// dest = conback->data + 320 - 43 + 320*186; // 2001-10-25 Version printing fix by Maddes
#endif
dest = conback->data + 320*186 + 320 - 11 - 8*strlen(ver); // 2001-10-25 Version printing fix by Maddes
for (x=0 ; x<strlen(ver) ; x++)
Draw_CharToConback (ver[x], dest+(x<<3));
// draw the pic
if (r_pixbytes == 1)
{
dest = vid.conbuffer;
for (y=0 ; y<lines ; y++, dest += vid.conrowbytes)
{
v = (vid.conheight - lines + y)*200/vid.conheight;
src = conback->data + v*320;
// 2000-08-04 "Transparent" console background for software renderer by Norberto Alfredo Bensa/Maddes start
/*
if (vid.conwidth == 320)
memcpy (dest, src, vid.conwidth);
else
{
*/
// 2000-08-04 "Transparent" console background for software renderer by Norberto Alfredo Bensa/Maddes end
f = 0;
fstep = 320*0x10000/vid.conwidth;
// 2000-08-04 "Transparent" console background for software renderer by Norberto Alfredo Bensa/Maddes start
if (con_forcedup)
{
for (x = 0; x < vid.conwidth; x++, f+=fstep )
dest[x] = src[f >> 16];
}
else
{
int t;
t = con_alpha->value * (float)CON_ALPHASTATES;
if (t >= CON_ALPHASTATES)
{
t = CON_ALPHASTATES - 1;
}
t = fademask[t]>>((y&1)<<2);
// 2000-08-04 "Transparent" console background for software renderer by Norberto Alfredo Bensa/Maddes end
for (x=0 ; x<vid.conwidth ; x+=4)
{
// 2000-08-04 "Transparent" console background for software renderer by Norberto Alfredo Bensa/Maddes start
/*
dest[x] = src[f>>16];
f += fstep;
dest[x+1] = src[f>>16];
f += fstep;
dest[x+2] = src[f>>16];
f += fstep;
dest[x+3] = src[f>>16];
f += fstep;
*/
if (t&1) dest[x] = src[f>>16]; f+=fstep;
if (t&2) dest[x+1] = src[f>>16]; f+=fstep;
if (t&4) dest[x+2] = src[f>>16]; f+=fstep;
if (t&8) dest[x+3] = src[f>>16]; f+=fstep;
// 2000-08-04 "Transparent" console background for software renderer by Norberto Alfredo Bensa/Maddes end
}
}
}
}
else
{
pusdest = (unsigned short *)vid.conbuffer;
for (y=0 ; y<lines ; y++, pusdest += (vid.conrowbytes >> 1))
{
// FIXME: pre-expand to native format?
// FIXME: does the endian switching go away in production?
v = (vid.conheight - lines + y)*200/vid.conheight;
src = conback->data + v*320;
f = 0;
fstep = 320*0x10000/vid.conwidth;
for (x=0 ; x<vid.conwidth ; x+=4)
{
pusdest[x] = d_8to16table[src[f>>16]];
f += fstep;
pusdest[x+1] = d_8to16table[src[f>>16]];
f += fstep;
pusdest[x+2] = d_8to16table[src[f>>16]];
f += fstep;
pusdest[x+3] = d_8to16table[src[f>>16]];
f += fstep;
}
}
}
}
/*
==============
R_DrawRect8
==============
*/
void R_DrawRect8 (vrect_t *prect, int rowbytes, byte *psrc,
int transparent)
{
byte t;
int i, j, srcdelta, destdelta;
byte *pdest;
pdest = vid.buffer + (prect->y * vid.rowbytes) + prect->x;
srcdelta = rowbytes - prect->width;
destdelta = vid.rowbytes - prect->width;
if (transparent)
{
for (i=0 ; i<prect->height ; i++)
{
for (j=0 ; j<prect->width ; j++)
{
t = *psrc;
if (t != TRANSPARENT_COLOR)
{
*pdest = t;
}
psrc++;
pdest++;
}
psrc += srcdelta;
pdest += destdelta;
}
}
else
{
for (i=0 ; i<prect->height ; i++)
{
memcpy (pdest, psrc, prect->width);
psrc += rowbytes;
pdest += vid.rowbytes;
}
}
}
/*
==============
R_DrawRect16
==============
*/
void R_DrawRect16 (vrect_t *prect, int rowbytes, byte *psrc,
int transparent)
{
byte t;
int i, j, srcdelta, destdelta;
unsigned short *pdest;
// FIXME: would it be better to pre-expand native-format versions?
pdest = (unsigned short *)vid.buffer +
(prect->y * (vid.rowbytes >> 1)) + prect->x;
srcdelta = rowbytes - prect->width;
destdelta = (vid.rowbytes >> 1) - prect->width;
if (transparent)
{
for (i=0 ; i<prect->height ; i++)
{
for (j=0 ; j<prect->width ; j++)
{
t = *psrc;
if (t != TRANSPARENT_COLOR)
{
*pdest = d_8to16table[t];
}
psrc++;
pdest++;
}
psrc += srcdelta;
pdest += destdelta;
}
}
else
{
for (i=0 ; i<prect->height ; i++)
{
for (j=0 ; j<prect->width ; j++)
{
*pdest = d_8to16table[*psrc];
psrc++;
pdest++;
}
psrc += srcdelta;
pdest += destdelta;
}
}
}
/*
=============
Draw_TileClear
This repeats a 64*64 tile graphic to fill the screen around a sized down
refresh window.
=============
*/
void Draw_TileClear (int x, int y, int w, int h)
{
int width, height, tileoffsetx, tileoffsety;
byte *psrc;
vrect_t vr;
r_rectdesc.rect.x = x;
r_rectdesc.rect.y = y;
r_rectdesc.rect.width = w;
r_rectdesc.rect.height = h;
vr.y = r_rectdesc.rect.y;
height = r_rectdesc.rect.height;
tileoffsety = vr.y % r_rectdesc.height;
while (height > 0)
{
vr.x = r_rectdesc.rect.x;
width = r_rectdesc.rect.width;
if (tileoffsety != 0)
vr.height = r_rectdesc.height - tileoffsety;
else
vr.height = r_rectdesc.height;
if (vr.height > height)
vr.height = height;
tileoffsetx = vr.x % r_rectdesc.width;
while (width > 0)
{
if (tileoffsetx != 0)
vr.width = r_rectdesc.width - tileoffsetx;
else
vr.width = r_rectdesc.width;
if (vr.width > width)
vr.width = width;
psrc = r_rectdesc.ptexbytes +
(tileoffsety * r_rectdesc.rowbytes) + tileoffsetx;
if (r_pixbytes == 1)
{
R_DrawRect8 (&vr, r_rectdesc.rowbytes, psrc, 0);
}
else
{
R_DrawRect16 (&vr, r_rectdesc.rowbytes, psrc, 0);
}
vr.x += vr.width;
width -= vr.width;
tileoffsetx = 0; // only the left tile can be left-clipped
}
vr.y += vr.height;
height -= vr.height;
tileoffsety = 0; // only the top tile can be top-clipped
}
}
/*
=============
Draw_Fill
Fills a box of pixels with a single color
=============
*/
void Draw_Fill (int x, int y, int w, int h, int c)
{
byte *dest;
unsigned short *pusdest;
unsigned uc;
int u, v;
if (r_pixbytes == 1)
{
dest = vid.buffer + y*vid.rowbytes + x;
for (v=0 ; v<h ; v++, dest += vid.rowbytes)
for (u=0 ; u<w ; u++)
dest[u] = c;
}
else
{
uc = d_8to16table[c];
pusdest = (unsigned short *)vid.buffer + y * (vid.rowbytes >> 1) + x;
for (v=0 ; v<h ; v++, pusdest += (vid.rowbytes >> 1))
for (u=0 ; u<w ; u++)
pusdest[u] = uc;
}
}
//=============================================================================
/*
================
Draw_FadeScreen
================
*/
void Draw_FadeScreen (void)
{
int x,y;
byte *pbuf;
VID_UnlockBuffer ();
S_ExtraUpdate ();
VID_LockBuffer ();
for (y=0 ; y<vid.height ; y++)
{
int t;
pbuf = (byte *)(vid.buffer + vid.rowbytes*y);
t = (y & 1) << 1;
for (x=0 ; x<vid.width ; x++)
{
if ((x & 3) != t)
pbuf[x] = 0;
}
}
VID_UnlockBuffer ();
S_ExtraUpdate ();
VID_LockBuffer ();
}
//=============================================================================
/*
================
Draw_BeginDisc
Draws the little blue disc in the corner of the screen.
Call before beginning any disc IO.
================
*/
void Draw_BeginDisc (void)
{
D_BeginDirectRect (vid.width - 24, 0, draw_disc->data, 24, 24);
}
/*
================
Draw_EndDisc
Erases the disc icon.
Call after completing any disc IO
================
*/
void Draw_EndDisc (void)
{
D_EndDirectRect (vid.width - 24, 0, 24, 24);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?