***map loader generates portals for the map*** (can you tell this is a big deal? :)
[xonotic/darkplaces.git] / r_sprites.c
1 #include "quakedef.h"
2
3 void GL_DrawSpriteImage (mspriteframe_t *frame, vec3_t origin, vec3_t up, vec3_t right, byte red, byte green, byte blue, int alpha)
4 {
5         byte alphaub;
6         alphaub = bound(0, alpha, 255);
7         transpolybegin(R_GetTexture(frame->texture), 0, R_GetTexture(frame->fogtexture), currententity->render.effects & EF_ADDITIVE ? TPOLYTYPE_ADD : TPOLYTYPE_ALPHA);
8         transpolyvertub(origin[0] + frame->down * up[0] + frame->left * right[0], origin[1] + frame->down * up[1] + frame->left * right[1], origin[2] + frame->down * up[2] + frame->left * right[2], 0, 1, red, green, blue, alphaub);
9         transpolyvertub(origin[0] + frame->up * up[0] + frame->left * right[0], origin[1] + frame->up * up[1] + frame->left * right[1], origin[2] + frame->up * up[2] + frame->left * right[2], 0, 0, red, green, blue, alphaub);
10         transpolyvertub(origin[0] + frame->up * up[0] + frame->right * right[0], origin[1] + frame->up * up[1] + frame->right * right[1], origin[2] + frame->up * up[2] + frame->right * right[2], 1, 0, red, green, blue, alphaub);
11         transpolyvertub(origin[0] + frame->down * up[0] + frame->right * right[0], origin[1] + frame->down * up[1] + frame->right * right[1], origin[2] + frame->down * up[2] + frame->right * right[2], 1, 1, red, green, blue, alphaub);
12         transpolyend();
13 }
14
15 /*
16 =================
17 R_DrawSpriteModel
18
19 =================
20 */
21 void R_DrawSpriteModel (entity_t *e, frameblend_t *blend)
22 {
23         vec3_t                  right, up, org, color, mins, maxs;
24         byte                    colorub[4];
25         msprite_t               *psprite;
26
27         VectorAdd (e->render.origin, e->render.model->mins, mins);
28         VectorAdd (e->render.origin, e->render.model->maxs, maxs);
29
30         if (R_VisibleCullBox (mins, maxs))
31                 return;
32
33         c_sprites++;
34
35         psprite = Mod_Extradata(e->render.model);
36         //psprite = e->model->cache.data;
37
38         if (psprite->type == SPR_ORIENTED)
39         {       // bullet marks on walls
40                 AngleVectors (e->render.angles, NULL, right, up);
41                 VectorSubtract(e->render.origin, vpn, org);
42         }
43         else
44         {       // normal sprite
45                 VectorCopy(vup, up);
46                 VectorCopy(vright, right);
47                 VectorCopy(e->render.origin, org);
48         }
49         if (e->render.scale != 1)
50         {
51                 VectorScale(up, e->render.scale, up);
52                 VectorScale(right, e->render.scale, right);
53         }
54
55         if (e->render.model->flags & EF_FULLBRIGHT || e->render.effects & EF_FULLBRIGHT)
56         {
57                 color[0] = e->render.colormod[0] * 255;
58                 color[1] = e->render.colormod[1] * 255;
59                 color[2] = e->render.colormod[2] * 255;
60         }
61         else
62                 R_CompleteLightPoint(color, e->render.origin, true);
63
64         colorub[0] = bound(0, color[0], 255);
65         colorub[1] = bound(0, color[1], 255);
66         colorub[2] = bound(0, color[2], 255);
67
68         // LordHavoc: interpolated sprite rendering
69         if (blend[0].lerp)
70                 GL_DrawSpriteImage(((mspriteframe_t *)(psprite->ofs_frames + (int) psprite)) + blend[0].frame, org, up, right, colorub[0],colorub[1],colorub[2], e->render.alpha*255*blend[0].lerp);
71         if (blend[1].lerp)
72                 GL_DrawSpriteImage(((mspriteframe_t *)(psprite->ofs_frames + (int) psprite)) + blend[1].frame, org, up, right, colorub[0],colorub[1],colorub[2], e->render.alpha*255*blend[1].lerp);
73         if (blend[2].lerp)
74                 GL_DrawSpriteImage(((mspriteframe_t *)(psprite->ofs_frames + (int) psprite)) + blend[2].frame, org, up, right, colorub[0],colorub[1],colorub[2], e->render.alpha*255*blend[2].lerp);
75         if (blend[3].lerp)
76                 GL_DrawSpriteImage(((mspriteframe_t *)(psprite->ofs_frames + (int) psprite)) + blend[3].frame, org, up, right, colorub[0],colorub[1],colorub[2], e->render.alpha*255*blend[3].lerp);
77 }
78