a big change with a little description...
[divverent/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;
24         byte                    colorub[4];
25         msprite_t               *psprite;
26
27         // don't even bother culling, because it's just a single
28         // polygon without a surface cache
29
30         c_sprites++;
31
32         psprite = Mod_Extradata(e->render.model);
33         //psprite = e->model->cache.data;
34
35         if (psprite->type == SPR_ORIENTED)
36         {       // bullet marks on walls
37                 AngleVectors (e->render.angles, NULL, right, up);
38                 VectorSubtract(e->render.origin, vpn, org);
39         }
40         else
41         {       // normal sprite
42                 VectorCopy(vup, up);
43                 VectorCopy(vright, right);
44                 VectorCopy(e->render.origin, org);
45         }
46         if (e->render.scale != 1)
47         {
48                 VectorScale(up, e->render.scale, up);
49                 VectorScale(right, e->render.scale, right);
50         }
51
52         if (e->render.model->flags & EF_FULLBRIGHT || e->render.effects & EF_FULLBRIGHT)
53         {
54                 color[0] = e->render.colormod[0] * 255;
55                 color[1] = e->render.colormod[1] * 255;
56                 color[2] = e->render.colormod[2] * 255;
57         }
58         else
59                 R_CompleteLightPoint(color, e->render.origin, true);
60
61         colorub[0] = bound(0, color[0], 255);
62         colorub[1] = bound(0, color[1], 255);
63         colorub[2] = bound(0, color[2], 255);
64
65         // LordHavoc: interpolated sprite rendering
66         if (blend[0].lerp)
67                 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);
68         if (blend[1].lerp)
69                 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);
70         if (blend[2].lerp)
71                 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);
72         if (blend[3].lerp)
73                 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);
74 }
75