-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgl_sprite.cpp
More file actions
127 lines (98 loc) · 3.37 KB
/
gl_sprite.cpp
File metadata and controls
127 lines (98 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
Copyright (C) 1996-1997 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// gl_sprite.c
//Code to do with sprites
#include "quakedef.h"
/*
=============================================================
SPRITE MODELS
=============================================================
*/
mspriteframe_t *R_GetSpriteFrame(entity_t *e) {
msprite_t *psprite;
mspritegroup_t *pspritegroup;
mspriteframe_t *pspriteframe;
int i, numframes, frame;
float *pintervals, fullinterval, targettime, time;
psprite = (msprite_t *) e->model->cache->getData();
frame = e->frame;
if ((frame >= psprite->numframes) || (frame < 0)) {
Con_Printf("R_DrawSprite: no such frame %d\n", frame);
frame = 0;
}
if (psprite->frames[frame].type == SPR_SINGLE) {
pspriteframe = psprite->frames[frame].frameptr;
} else {
pspritegroup = (mspritegroup_t *) psprite->frames[frame].frameptr;
pintervals = pspritegroup->intervals;
numframes = pspritegroup->numframes;
fullinterval = pintervals[numframes - 1];
time = cl.time + e->syncbase;
// when loading in Mod_LoadSpriteGroup, we guaranteed all interval values
// are positive, so we don't have to worry about division by 0
targettime = time - ((int) (time / fullinterval)) * fullinterval;
for (i = 0; i < (numframes - 1); i++) {
if (pintervals[i] > targettime)
break;
}
pspriteframe = pspritegroup->frames[i];
}
return pspriteframe;
}
void R_DrawSpriteModel(entity_t *e) {
vec3_t point;
mspriteframe_t *frame;
float *up, *right;
vec3_t v_forward, v_right, v_up;
msprite_t *psprite;
// don't even bother culling, because it's just a single
// polygon without a surface cache
frame = R_GetSpriteFrame(e);
psprite = (msprite_t *) e->model->cache->getData();
if (psprite->type == SPR_ORIENTED) { // bullet marks on walls
AngleVectors(e->angles, v_forward, v_right, v_up);
up = v_up;
right = v_right;
} else { // normal sprite
up = vup;
right = vright;
}
glColor3f(1, 1, 1);
glBindTexture(GL_TEXTURE_2D, frame->gl_texturenum);
glDepthMask(0);
glEnable(GL_BLEND);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBegin(GL_QUADS);
glTexCoord2f(0, 1);
VectorMA(e->origin, frame->down, up, point);
VectorMA(point, frame->left, right, point);
glVertex3fv(point);
glTexCoord2f(0, 0);
VectorMA(e->origin, frame->up, up, point);
VectorMA(point, frame->left, right, point);
glVertex3fv(point);
glTexCoord2f(1, 0);
VectorMA(e->origin, frame->up, up, point);
VectorMA(point, frame->right, right, point);
glVertex3fv(point);
glTexCoord2f(1, 1);
VectorMA(e->origin, frame->down, up, point);
VectorMA(point, frame->right, right, point);
glVertex3fv(point);
glEnd();
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glDepthMask(1);
glDisable(GL_BLEND);
}