2 //**************************************************************************
4 //** r_draw.c : Heretic 2 : Raven Software, Corp.
11 //**************************************************************************
22 All drawing to the view buffer is accomplished in this file. The other refresh
23 files only know about ccordinates, not the architecture of the frame buffer.
28 int viewwidth, scaledviewwidth, viewheight, viewwindowx, viewwindowy;
29 byte *ylookup[MAXHEIGHT];
30 int columnofs[MAXWIDTH];
31 //byte translations[3][256]; // color tables for different players
32 byte *tinttable; // used for translucent sprites
42 = Source is the top of the column to scale
47 lighttable_t *dc_colormap;
52 fixed_t dc_texturemid;
53 byte *dc_source; // first pixel in a column (possibly virtual)
55 int dccount; // just for profiling
58 // #ifndef __i386 These seem to be useless. DDOI - 1/2/00
60 void R_DrawColumn (void)
64 fixed_t frac, fracstep;
66 count = dc_yh - dc_yl;
71 if ((unsigned)dc_x >= SCREENWIDTH || dc_yl < 0 || dc_yh >= SCREENHEIGHT)
72 I_Error ("R_DrawColumn: %i to %i at %i", dc_yl, dc_yh, dc_x);
75 dest = ylookup[dc_yl] + columnofs[dc_x];
78 frac = dc_texturemid + (dc_yl-centery)*fracstep;
82 *dest = dc_colormap[dc_source[(frac>>FRACBITS)&127]];
91 void R_DrawColumnLow (void)
95 fixed_t frac, fracstep;
97 count = dc_yh - dc_yl;
102 if ((unsigned)dc_x >= SCREENWIDTH || dc_yl < 0 || dc_yh >= SCREENHEIGHT)
103 I_Error ("R_DrawColumn: %i to %i at %i", dc_yl, dc_yh, dc_x);
107 dest = ylookup[dc_yl] + columnofs[dc_x];
109 fracstep = dc_iscale;
110 frac = dc_texturemid + (dc_yl-centery)*fracstep;
114 *dest = dc_colormap[dc_source[(frac>>FRACBITS)&127]];
122 #define FUZZOFF (SCREENWIDTH)
123 int fuzzoffset[FUZZTABLE] = {
124 FUZZOFF,-FUZZOFF,FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,-FUZZOFF,-FUZZOFF,-FUZZOFF,FUZZOFF,-FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,-FUZZOFF,-FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,FUZZOFF
130 void R_DrawFuzzColumn (void)
134 fixed_t frac, fracstep;
138 if (dc_yh == viewheight-1)
139 dc_yh = viewheight - 2;
141 count = dc_yh - dc_yl;
146 if ((unsigned)dc_x >= SCREENWIDTH || dc_yl < 0 || dc_yh >= SCREENHEIGHT)
147 I_Error ("R_DrawFuzzColumn: %i to %i at %i", dc_yl, dc_yh, dc_x);
150 dest = ylookup[dc_yl] + columnofs[dc_x];
152 fracstep = dc_iscale;
153 frac = dc_texturemid + (dc_yl-centery)*fracstep;
155 // OLD FUZZY INVISO SPRITE STUFF
158 *dest = colormaps[6*256+dest[fuzzoffset[fuzzpos]]];
159 if (++fuzzpos == FUZZTABLE)
168 *dest = tinttable[*dest+
169 (dc_colormap[dc_source[(frac>>FRACBITS)&127]]<<8)];
176 //============================================================================
178 // R_DrawAltFuzzColumn
180 //============================================================================
182 void R_DrawAltFuzzColumn (void)
186 fixed_t frac, fracstep;
190 if (dc_yh == viewheight-1)
191 dc_yh = viewheight - 2;
193 count = dc_yh - dc_yl;
198 if ((unsigned)dc_x >= SCREENWIDTH || dc_yl < 0 || dc_yh >= SCREENHEIGHT)
199 I_Error ("R_DrawFuzzColumn: %i to %i at %i", dc_yl, dc_yh, dc_x);
202 dest = ylookup[dc_yl] + columnofs[dc_x];
204 fracstep = dc_iscale;
205 frac = dc_texturemid + (dc_yl-centery)*fracstep;
209 *dest = tinttable[((*dest)<<8)
210 +dc_colormap[dc_source[(frac>>FRACBITS)&127]]];
217 ========================
219 = R_DrawTranslatedColumn
221 ========================
224 byte *dc_translation;
225 byte *translationtables;
227 void R_DrawTranslatedColumn (void)
231 fixed_t frac, fracstep;
233 count = dc_yh - dc_yl;
238 if ((unsigned)dc_x >= SCREENWIDTH || dc_yl < 0 || dc_yh >= SCREENHEIGHT)
239 I_Error ("R_DrawColumn: %i to %i at %i", dc_yl, dc_yh, dc_x);
242 dest = ylookup[dc_yl] + columnofs[dc_x];
244 fracstep = dc_iscale;
245 frac = dc_texturemid + (dc_yl-centery)*fracstep;
249 *dest = dc_colormap[dc_translation[dc_source[frac>>FRACBITS]]];
255 //============================================================================
257 // R_DrawTranslatedFuzzColumn
259 //============================================================================
261 void R_DrawTranslatedFuzzColumn (void)
265 fixed_t frac, fracstep;
267 count = dc_yh - dc_yl;
272 if ((unsigned)dc_x >= SCREENWIDTH || dc_yl < 0 || dc_yh >= SCREENHEIGHT)
273 I_Error ("R_DrawColumn: %i to %i at %i", dc_yl, dc_yh, dc_x);
276 dest = ylookup[dc_yl] + columnofs[dc_x];
278 fracstep = dc_iscale;
279 frac = dc_texturemid + (dc_yl-centery)*fracstep;
283 *dest = tinttable[((*dest)<<8)
284 +dc_colormap[dc_translation[dc_source[frac>>FRACBITS]]]];
290 //============================================================================
292 // R_DrawTranslatedAltFuzzColumn
294 //============================================================================
297 void R_DrawTranslatedAltFuzzColumn (void)
301 fixed_t frac, fracstep;
303 count = dc_yh - dc_yl;
308 if ((unsigned)dc_x >= SCREENWIDTH || dc_yl < 0 || dc_yh >= SCREENHEIGHT)
309 I_Error ("R_DrawColumn: %i to %i at %i", dc_yl, dc_yh, dc_x);
312 dest = ylookup[dc_yl] + columnofs[dc_x];
314 fracstep = dc_iscale;
315 frac = dc_texturemid + (dc_yl-centery)*fracstep;
319 *dest = tinttable[*dest
320 +(dc_colormap[dc_translation[dc_source[frac>>FRACBITS]]]<<8)];
327 //--------------------------------------------------------------------------
329 // PROC R_InitTranslationTables
331 //--------------------------------------------------------------------------
333 void R_InitTranslationTables (void)
339 tinttable = W_CacheLumpName("TINTTAB", PU_STATIC);
341 // Allocate translation tables
342 translationtables = Z_Malloc(256*3*(MAXPLAYERS-1)+255,
344 translationtables = (byte *)(((int)translationtables+255)&~255);
346 for(i = 0; i < 3*(MAXPLAYERS-1); i++)
348 transLump = W_CacheLumpNum(W_GetNumForName("trantbl0")+i, PU_STATIC);
349 memcpy(translationtables+i*256, transLump, 256);
365 lighttable_t *ds_colormap;
370 byte *ds_source; // start of a 64*64 tile image
372 int dscount; // just for profiling
377 void R_DrawSpan (void)
379 fixed_t xfrac, yfrac;
384 if (ds_x2 < ds_x1 || ds_x1<0 || ds_x2>=SCREENWIDTH
385 || (unsigned)ds_y>SCREENHEIGHT)
386 I_Error ("R_DrawSpan: %i to %i at %i",ds_x1,ds_x2,ds_y);
393 dest = ylookup[ds_y] + columnofs[ds_x1];
394 count = ds_x2 - ds_x1;
397 spot = ((yfrac>>(16-6))&(63*64)) + ((xfrac>>16)&63);
398 *dest++ = ds_colormap[ds_source[spot]];
406 void R_DrawSpanLow (void)
408 fixed_t xfrac, yfrac;
413 if (ds_x2 < ds_x1 || ds_x1<0 || ds_x2>=SCREENWIDTH
414 || (unsigned)ds_y>SCREENHEIGHT)
415 I_Error ("R_DrawSpan: %i to %i at %i",ds_x1,ds_x2,ds_y);
422 dest = ylookup[ds_y] + columnofs[ds_x1];
423 count = ds_x2 - ds_x1;
426 spot = ((yfrac>>(16-6))&(63*64)) + ((xfrac>>16)&63);
427 *dest++ = ds_colormap[ds_source[spot]];
445 void R_InitBuffer (int width, int height)
449 viewwindowx = (SCREENWIDTH-width) >> 1;
450 for (i=0 ; i<width ; i++)
451 columnofs[i] = viewwindowx + i;
452 if (width == SCREENWIDTH)
455 viewwindowy = (SCREENHEIGHT-SBARHEIGHT-height) >> 1;
456 for (i=0 ; i<height ; i++)
457 ylookup[i] = screen + (i+viewwindowy)*SCREENWIDTH;
466 = Draws the border around the view for different size windows
470 boolean BorderNeedRefresh;
472 void R_DrawViewBorder (void)
478 if (scaledviewwidth == SCREENWIDTH)
481 if((scaledviewwidth == 320 && sbarscale == 20) ||
482 (sbarscale != 20 && viewheight == 200))
487 OGL_SetColorAndAlpha(1,1,1,1);
488 OGL_SetFlat(W_GetNumForName("F_022")-firstflat);
491 OGL_DrawCutRectTiled(0, 0, 320, 200 - SBARHEIGHT, 64, 64,
492 viewwindowx-4, viewwindowy-4, viewwidth+8, viewheight+8);
494 //OGL_DrawRectTiled(0, 0, SCREENWIDTH, SCREENHEIGHT-SBARHEIGHT, 64, 64);
495 OGL_DrawCutRectTiled(0, 0, 320, 200 - (sbarscale==20? SBARHEIGHT : 0)
496 /**sbarscale/20*/, 64, 64,
497 viewwindowx-4, viewwindowy-4, viewwidth+8, viewheight+8);
501 OGL_SetPatch(lump=W_GetNumForName("bordt"));
502 OGL_DrawRectTiled(viewwindowx, viewwindowy-4, viewwidth,
503 lumptexsizes[lump].h, 16, lumptexsizes[lump].h);
505 OGL_SetPatch(lump=W_GetNumForName("bordb"));
506 OGL_DrawRectTiled(viewwindowx, viewwindowy+viewheight, viewwidth,
507 lumptexsizes[lump].h, 16, lumptexsizes[lump].h);
510 OGL_SetPatch(lump=W_GetNumForName("bordl"));
511 OGL_DrawRectTiled(viewwindowx-4, viewwindowy, lumptexsizes[lump].w,
512 viewheight, lumptexsizes[lump].w, 16);
513 // Right view border.
514 OGL_SetPatch(lump=W_GetNumForName("bordr"));
515 OGL_DrawRectTiled(viewwindowx+viewwidth, viewwindowy,
516 lumptexsizes[lump].w,
517 viewheight, lumptexsizes[lump].w, 16);
519 OGL_DrawPatch(viewwindowx-4, viewwindowy-4, W_GetNumForName("bordtl"));
520 OGL_DrawPatch(viewwindowx+viewwidth, viewwindowy-4,
521 W_GetNumForName("bordtr"));
522 OGL_DrawPatch(viewwindowx+viewwidth, viewwindowy+viewheight,
523 W_GetNumForName("bordbr"));
525 OGL_DrawPatch(viewwindowx-4, viewwindowy+viewheight,
526 W_GetNumForName("bordbl"));
533 if (scaledviewwidth == SCREENWIDTH)
536 src = W_CacheLumpName("F_022", PU_CACHE);
539 for (y=0 ; y<SCREENHEIGHT-SBARHEIGHT ; y++)
541 for (x=0 ; x<SCREENWIDTH/64 ; x++)
543 memcpy (dest, src+((y&63)<<6), 64);
548 memcpy (dest, src+((y&63)<<6), SCREENWIDTH&63);
549 dest += (SCREENWIDTH&63);
552 for(x=viewwindowx; x < viewwindowx+viewwidth; x += 16)
554 V_DrawPatch(x, viewwindowy-4, W_CacheLumpName("bordt", PU_CACHE));
555 V_DrawPatch(x, viewwindowy+viewheight, W_CacheLumpName("bordb",
558 for(y=viewwindowy; y < viewwindowy+viewheight; y += 16)
560 V_DrawPatch(viewwindowx-4, y, W_CacheLumpName("bordl", PU_CACHE));
561 V_DrawPatch(viewwindowx+viewwidth, y, W_CacheLumpName("bordr",
564 V_DrawPatch(viewwindowx-4, viewwindowy-4, W_CacheLumpName("bordtl",
566 V_DrawPatch(viewwindowx+viewwidth, viewwindowy-4,
567 W_CacheLumpName("bordtr", PU_CACHE));
568 V_DrawPatch(viewwindowx+viewwidth, viewwindowy+viewheight,
569 W_CacheLumpName("bordbr", PU_CACHE));
570 V_DrawPatch(viewwindowx-4, viewwindowy+viewheight,
571 W_CacheLumpName("bordbl", PU_CACHE));
580 = Draws the top border around the view for different size windows
584 boolean BorderTopRefresh;
586 void R_DrawTopBorder (void)
589 if (scaledviewwidth == SCREENWIDTH)
592 OGL_SetColorAndAlpha( 1,1,1,1 );
593 OGL_SetFlat( W_GetNumForName("F_022") - firstflat );
595 OGL_DrawRectTiled(0, 0, 320, 64, 64, 64);
596 if( viewwindowy < 65 )
599 OGL_SetPatch(lump=W_GetNumForName("bordt"));
600 OGL_DrawRectTiled(viewwindowx, viewwindowy-4, viewwidth,
601 lumptexsizes[lump].h, 16, lumptexsizes[lump].h);
603 OGL_DrawPatch(viewwindowx-4, viewwindowy, W_GetNumForName("bordl"));
604 OGL_DrawPatch(viewwindowx+viewwidth, viewwindowy,
605 W_GetNumForName("bordr"));
606 OGL_DrawPatch(viewwindowx-4, viewwindowy+16,
607 W_GetNumForName("bordl"));
608 OGL_DrawPatch(viewwindowx+viewwidth, viewwindowy+16,
609 W_GetNumForName("bordr"));
611 OGL_DrawPatch(viewwindowx-4, viewwindowy-4,
612 W_GetNumForName("bordtl"));
613 OGL_DrawPatch(viewwindowx+viewwidth, viewwindowy-4,
614 W_GetNumForName("bordtr"));//, PU_CACHE));
622 if (scaledviewwidth == SCREENWIDTH)
627 src = W_CacheLumpName ("FLOOR04", PU_CACHE);
631 src = W_CacheLumpName ("FLAT513", PU_CACHE);
634 src = W_CacheLumpName("F_022", PU_CACHE);
637 for (y=0 ; y<34 ; y++)
639 for (x=0 ; x<SCREENWIDTH/64 ; x++)
641 memcpy (dest, src+((y&63)<<6), 64);
646 memcpy (dest, src+((y&63)<<6), SCREENWIDTH&63);
647 dest += (SCREENWIDTH&63);
652 for(x=viewwindowx; x < viewwindowx+viewwidth; x += 16)
654 V_DrawPatch(x, viewwindowy-4, W_CacheLumpName("bordt", PU_CACHE));
656 V_DrawPatch(viewwindowx-4, viewwindowy, W_CacheLumpName("bordl",
658 V_DrawPatch(viewwindowx+viewwidth, viewwindowy,
659 W_CacheLumpName("bordr", PU_CACHE));
660 V_DrawPatch(viewwindowx-4, viewwindowy+16, W_CacheLumpName("bordl",
662 V_DrawPatch(viewwindowx+viewwidth, viewwindowy+16,
663 W_CacheLumpName("bordr", PU_CACHE));
665 V_DrawPatch(viewwindowx-4, viewwindowy-4, W_CacheLumpName("bordtl",
667 V_DrawPatch(viewwindowx+viewwidth, viewwindowy-4,
668 W_CacheLumpName("bordtr", PU_CACHE));