UFO: Alien Invasion
Loading...
Searching...
No Matches
r_corona.cpp
Go to the documentation of this file.
1/*
2 * Copyright(c) 1997-2001 Id Software, Inc.
3 * Copyright(c) 2002 The Quakeforge Project.
4 * Copyright(c) 2006 Quake2World.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 *
15 * See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#include "r_local.h"
23
24void R_AddCorona (const vec3_t org, float radius, const vec3_t color)
25{
26 corona_t* c;
27
28 if (!r_coronas->integer)
29 return;
30
31 if (refdef.numCoronas == MAX_CORONAS)
32 return;
33
34 c = &refdef.coronas[refdef.numCoronas++];
35
36 VectorCopy(org, c->org);
37 c->radius = radius;
38 VectorCopy(color, c->color);
39}
40
41void R_DrawCoronas (void)
42{
43 if (!r_coronas->integer)
44 return;
45
46 if (!refdef.numCoronas)
47 return;
48
50
52
54
55 R_BlendFunc(GL_ONE, GL_ONE);
56
57 for (int k = 0; k < refdef.numCoronas; k++) {
58 const corona_t* c = &refdef.coronas[k];
59 int verts, vertind;
60
61 if (!c->radius)
62 continue;
63
64 /* use at least 12 verts, more for larger coronas */
65 verts = 12 + c->radius / 8;
66
67 memcpy(&r_state.color_array[0], c->color, sizeof(vec3_t));
68 r_state.color_array[3] = 1.0f; /* set origin color */
69
70 /* and the corner colors */
71 memset(&r_state.color_array[4], 0, verts * 2 * sizeof(vec4_t));
72
73 memcpy(&r_state.vertex_array_3d[0], c->org, sizeof(vec3_t));
74 vertind = 3; /* and the origin */
75
76 for (int i = verts; i >= 0; i--) { /* now draw the corners */
77 const float a = (M_PI * 2 / verts) * i;
78 vec3_t v;
79
80 for (int j = 0; j < 3; j++)
81 v[j] = c->org[j] + r_locals.right[j] * (float) cos(a) * c->radius + r_locals.up[j] * (float) sin(a)
82 * c->radius;
83
84 memcpy(&r_state.vertex_array_3d[vertind], v, sizeof(vec3_t));
85 vertind += 3;
86 }
87
88 glDrawArrays(GL_TRIANGLE_FAN, 0, vertind / 3);
89
90 refdef.batchCount++;
91 }
92
93 R_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
94
95 R_EnableColorArray(false);
96
98
99 R_Color(nullptr);
100}
rendererData_t refdef
Definition r_main.cpp:45
#define MAX_CORONAS
Definition cl_renderer.h:53
void R_Color(const vec4_t rgba)
Change the color to given value.
Definition r_state.cpp:1011
#define M_PI
Definition mathlib.h:34
void R_ResetArrayState(void)
Definition r_array.cpp:185
void R_AddCorona(const vec3_t org, float radius, const vec3_t color)
Definition r_corona.cpp:24
void R_DrawCoronas(void)
Definition r_corona.cpp:41
QGL_EXTERN int GLboolean GLfloat * v
Definition r_gl.h:120
QGL_EXTERN GLint i
Definition r_gl.h:113
local graphics definitions
cvar_t * r_coronas
Definition r_main.cpp:109
rlocals_t r_locals
Definition r_main.cpp:49
rstate_t r_state
Definition r_main.cpp:48
void R_EnableTexture(gltexunit_t *texunit, bool enable)
Definition r_state.cpp:303
void R_BlendFunc(GLenum src, GLenum dest)
Definition r_state.cpp:232
void R_EnableColorArray(bool enable)
Definition r_state.cpp:332
#define texunit_diffuse
Definition r_state.h:68
coronas are soft, alpha-blended, rounded polys
Definition cl_renderer.h:47
vec3_t color
Definition cl_renderer.h:50
vec3_t org
Definition cl_renderer.h:48
float radius
Definition cl_renderer.h:49
vec_t vec3_t[3]
Definition ufotypes.h:39
vec_t vec4_t[4]
Definition ufotypes.h:40
#define VectorCopy(src, dest)
Definition vector.h:51