⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 v_video.c

📁 The source code of Doom legacy for windows
💻 C
📖 第 1 页 / 共 3 页
字号:
    dx = FixedDiv(FRACUNIT,dupx<<FRACBITS);    dy = FixedDiv(FRACUNIT,dupy<<FRACBITS);    yfrac = 0;    for (v=0; v<h ; v++, dest += vid.width)    {        xfrac = 0;        src = flat + (((yfrac>>FRACBITS)&63)<<6);        for (u=0 ; u<w ; u++)        {            dest[u] = src[(xfrac>>FRACBITS)&63];            xfrac += dx;        }        yfrac += dy;    }}////  Fade all the screen buffer, so that the menu is more readable,//  especially now that we use the small hufont in the menus...//void V_DrawFadeScreen (void){    int         x,y,w;    int         *buf;    unsigned    quad;    byte        p1, p2, p3, p4;    byte*       fadetable = (byte *) colormaps + 16*256;    //short*    wput;#ifdef HWRENDER // not win32 only 19990829 by Kin    if (rendermode!=render_soft) {        HWR_FadeScreenMenuBack (0x01010160, 0);  //faB: hack, 0 means full height :o        return;    }#endif    w = vid.width>>2;    for (y=0 ; y<vid.height ; y++)    {        buf = (int *)(screens[0] + vid.width*y);        for (x=0 ; x<w ; x++)        {            quad = buf[x];            p1 = fadetable[quad&255];            p2 = fadetable[(quad>>8)&255];            p3 = fadetable[(quad>>16)&255];            p4 = fadetable[quad>>24];            buf[x] = (p4<<24) | (p3<<16) | (p2<<8) | p1;        }    }#ifdef _16bitcrapneverfinished else {    w = vid.width;    for (y=0 ; y<vid.height ; y++)    {        wput = (short*) (screens[0] + vid.width*y);        for (x=0 ; x<w ; x++)        {            *wput++ = (*wput>>1) & 0x3def;        }    } }#endif}// Simple translucence with one color, coords are resolution dependent////added:20-03-98: console testvoid V_DrawFadeConsBack (int x1, int y1, int x2, int y2){    int         x,y,w;    int         *buf;    unsigned    quad;    byte        p1, p2, p3, p4;    short*      wput; if (scr_bpp==1) {    x1 >>=2;    x2 >>=2;    for (y=y1 ; y<y2 ; y++)    {        buf = (int *)(screens[0] + vid.width*y);        for (x=x1 ; x<x2 ; x++)        {            quad = buf[x];            p1 = greenmap[quad&255];            p2 = greenmap[(quad>>8)&255];            p3 = greenmap[(quad>>16)&255];            p4 = greenmap[quad>>24];            buf[x] = (p4<<24) | (p3<<16) | (p2<<8) | p1;        }    } } else {    w = x2-x1;    for (y=y1 ; y<y2 ; y++)    {        wput = (short*)(screens[0] + vid.width*y) + x1;        for (x=0 ; x<w ; x++)        {            *wput++ = ((*wput&0x7bde) + (15<<5)) >>1;        }    } }}// Writes a single character (draw WHITE if bit 7 set)////added:20-03-98:void V_DrawCharacter (int x, int y, int c){    int         w;    int         flags;    boolean     white;    white = c & 0x80;    flags = c & 0xffff0000;    c &= 0x7f;    c = toupper(c) - HU_FONTSTART;    if (c < 0 || c>= HU_FONTSIZE)        return;    w = (hu_font[c]->width);    if (x+w > vid.width)        return;    if (white)        // draw with colormap, WITHOUT scale        V_DrawMappedPatch(x, y, 0|flags, hu_font[c], whitemap);    else        V_DrawScaledPatch(x, y, 0|flags, hu_font[c]);}////  Write a string using the hu_font//  NOTE: the text is centered for screens larger than the base width////added:05-02-98:void V_DrawString (int x, int y, char* string){    int         w;    char*       ch;    int         c;    int         cx;    int         cy;    ch = string;    cx = x;    cy = y;    while(1)    {        c = *ch++;        if (!c)            break;        if (c == '\n')        {            cx = x;            cy += 12;            continue;        }        c = toupper(c) - HU_FONTSTART;        if (c < 0 || c>= HU_FONTSIZE)        {            cx += 4;            continue;        }        w = (hu_font[c]->width);        if (cx+w > BASEVIDWIDTH)            break;        V_DrawScaledPatch(cx, cy, 0, hu_font[c]);        cx+=w;    }}////added:03-02-98: V_DrawString, using a colormap to display the text in//                brighter colors.void V_DrawStringWhite (int x, int y, char* string){    int         w;    char*       ch;    int         c;    int         cx;    int         cy;    ch = string;    cx = x;    cy = y;    while(1)    {        c = *ch++;        if (!c)            break;        if (c == '\n')        {            cx = x;            cy += 12;            continue;        }        c = toupper(c) - HU_FONTSTART;        if (c < 0 || c>= HU_FONTSIZE)        {            cx += 4;            continue;        }        w =  (hu_font[c]->width);        if (cx+w > vid.width)            break;        V_DrawMappedPatch(cx, cy, 0, hu_font[c], whitemap);        cx+=w;    }}//// Find string width from hu_font chars//int V_StringWidth (char* string){    int             i;    int             w = 0;    int             c;    for (i = 0;i < (int)strlen(string);i++)    {        c = toupper(string[i]) - HU_FONTSTART;        if (c < 0 || c >= HU_FONTSIZE)            w += 4;        else            w +=  (hu_font[c]->width);    }    return w;}//// Find string height from hu_font chars//int V_StringHeight (char* string){    return (hu_font[0]->height);}//---------------------------------------------------------------------------//// PROC MN_DrTextB//// Draw text using font B.////---------------------------------------------------------------------------int FontBBaseLump;void V_DrawTextB(char *text, int x, int y){    char c;    patch_t *p;        while((c = *text++) != 0)    {        if(c < 33)        {            x += 8;        }        else        {            p = W_CachePatchNum(FontBBaseLump+toupper(c)-33, PU_CACHE);            V_DrawScaledPatch(x, y, 0, p);            x += p->width-1;        }    }}void V_DrawTextBGray(char *text, int x, int y){    char c;    patch_t *p;        while((c = *text++) != 0)    {        if(c < 33)        {            x += 8;        }        else        {            p = W_CachePatchNum(FontBBaseLump+toupper(c)-33, PU_CACHE);            V_DrawMappedPatch(x, y, 0, p, graymap);            x += p->width-1;        }    }}//---------------------------------------------------------------------------//// FUNC MN_TextBWidth//// Returns the pixel width of a string using font B.////---------------------------------------------------------------------------int V_TextBWidth(char *text){    char c;    int width;    patch_t *p;        width = 0;    while((c = *text++) != 0)    {        if(c < 33)        {            width += 5;        }        else        {            p = W_CachePatchNum(FontBBaseLump+toupper(c)-33, PU_CACHE);            width += p->width-1;        }    }    return(width);}int V_TextBHeight(char *text){    return 16;}// V_Init// olf software stuff, buffers are allocated at video mode setup// here we set the screens[x] pointers accordingly// WARNING :// - called at runtime (don't init cvar here)void V_Init (void){    int         i;    byte*       base;    int         screensize;    LoadPalette();    FontBBaseLump = W_CheckNumForName("FONTB_S")+1;#ifdef HWRENDER // not win32 only 19990829 by Kin    // hardware modes do not use screens[] pointers    if (rendermode != render_soft)    {        // be sure to cause a NULL read/write error so we detect it, in case of..        for (i=0 ; i<NUMSCREENS ; i++)            screens[i] = NULL;        return;    }#endif        //added:26-01-98:start address of NUMSCREENS * width*height vidbuffers    base = vid.buffer;    screensize = vid.width * vid.height * vid.bpp;    for (i=0 ; i<NUMSCREENS ; i++)        screens[i] = base + i*screensize;    //added:26-01-98: statusbar buffer    screens[4] = base + NUMSCREENS*screensize; //!debug#ifdef DEBUG CONS_Printf("V_Init done:\n"); for(i=0;i<NUMSCREENS+1;i++)     CONS_Printf(" screens[%d] = %x\n",i,screens[i]);#endif}//////typedef struct {    int    px;    int    py;} modelvertex_t;void R_DrawSpanNoWrap (void);   //tmap.S////  Tilts the view like DukeNukem...////added:12-02-98:#ifdef TILTVIEW#ifdef HWRENDERvoid V_DrawTiltView (byte *viewbuffer)  // don't touch direct video I'll find something..{}#elsestatic modelvertex_t vertex[4];void V_DrawTiltView (byte *viewbuffer){    fixed_t    leftxfrac;    fixed_t    leftyfrac;    fixed_t    xstep;    fixed_t    ystep;    int        y;    vertex[0].px = 0;   // tl    vertex[0].py = 53;    vertex[1].px = 212; // tr    vertex[1].py = 0;    vertex[2].px = 264; // br    vertex[2].py = 144;    vertex[3].px = 53;  // bl    vertex[3].py = 199;    // resize coords to screen    for (y=0;y<4;y++)    {        vertex[y].px = (vertex[y].px * vid.width) / BASEVIDWIDTH;        vertex[y].py = (vertex[y].py * vid.height) / BASEVIDHEIGHT;    }    ds_colormap = fixedcolormap;    ds_source = viewbuffer;    // starting points top-left and top-right    leftxfrac  = vertex[0].px <<FRACBITS;    leftyfrac  = vertex[0].py <<FRACBITS;    // steps    xstep = ((vertex[3].px - vertex[0].px)<<FRACBITS) / vid.height;    ystep = ((vertex[3].py - vertex[0].py)<<FRACBITS) / vid.height;    ds_y  = (int) vid.direct;    ds_x1 = 0;    ds_x2 = vid.width-1;    ds_xstep = ((vertex[1].px - vertex[0].px)<<FRACBITS) / vid.width;    ds_ystep = ((vertex[1].py - vertex[0].py)<<FRACBITS) / vid.width;//    I_Error("ds_y %d ds_x1 %d ds_x2 %d ds_xstep %x ds_ystep %x \n"//            "ds_xfrac %x ds_yfrac %x ds_source %x\n", ds_y,//                      ds_x1,ds_x2,ds_xstep,ds_ystep,leftxfrac,leftyfrac,//                      ds_source);    // render spans    for (y=0; y<vid.height; y++)    {        // FAST ASM routine!        ds_xfrac = leftxfrac;        ds_yfrac = leftyfrac;        R_DrawSpanNoWrap ();        ds_y += vid.rowbytes;        // move along the left and right edges of the polygon        leftxfrac += xstep;        leftyfrac += ystep;    }}#endif#endif//// Test 'scrunch perspective correction' tm (c) ect.////added:05-04-98:#ifdef HWRENDER // not win32 only 19990829 by Kinvoid V_DrawPerspView (byte *viewbuffer, int aiming){}#elsevoid V_DrawPerspView (byte *viewbuffer, int aiming){     byte*      source;     byte*      dest;     int        y;     int        x1,w;     int        offs;     fixed_t    topfrac,bottomfrac,scale,scalestep;     fixed_t    xfrac,xfracstep;    source = viewbuffer;    //+16 to -16 fixed    offs = ((aiming*20)<<16) / 100;    topfrac    = ((vid.width-40)<<16) - (offs*2);    bottomfrac = ((vid.width-40)<<16) + (offs*2);    scalestep  = (bottomfrac-topfrac) / vid.height;    scale      = topfrac;    for (y=0; y<vid.height; y++)    {        x1 = ((vid.width<<16) - scale)>>17;        dest = ((byte*) vid.direct) + (vid.rowbytes*y) + x1;        xfrac = (20<<FRACBITS) + ((!x1)&0xFFFF);        xfracstep = FixedDiv((vid.width<<FRACBITS)-(xfrac<<1),scale);        w = scale>>16;        while (w--)        {            *dest++ = source[xfrac>>FRACBITS];            xfrac += xfracstep;        }        scale += scalestep;        source += vid.width;    }}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -