r_corona.c

Go to the documentation of this file.
00001 /*
00002  * Copyright(c) 1997-2001 Id Software, Inc.
00003  * Copyright(c) 2002 The Quakeforge Project.
00004  * Copyright(c) 2006 Quake2World.
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00014  *
00015  * See the GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020  */
00021 
00022 #include "r_local.h"
00023 
00024 void R_AddCorona (const vec3_t org, float radius, const vec3_t color)
00025 {
00026     corona_t *c;
00027 
00028     if (!r_coronas->value)
00029         return;
00030 
00031     if (refdef.numCoronas == MAX_CORONAS)
00032         return;
00033 
00034     c = &refdef.coronas[refdef.numCoronas++];
00035 
00036     VectorCopy(org, c->org);
00037     c->radius = radius;
00038     VectorCopy(color, c->color);
00039 }
00040 
00041 void R_DrawCoronas (void)
00042 {
00043     int i, j, k;
00044     vec3_t v;
00045 
00046     if (!r_coronas->integer)
00047         return;
00048 
00049     if (!refdef.numCoronas)
00050         return;
00051 
00052     R_EnableTexture(&texunit_diffuse, qfalse);
00053 
00054     R_EnableColorArray(qtrue);
00055 
00056     R_ResetArrayState();
00057 
00058     R_BlendFunc(GL_ONE, GL_ONE);
00059 
00060     for (k = 0; k < refdef.numCoronas; k++) {
00061         const corona_t *c = &refdef.coronas[k];
00062         int verts, vertind;
00063 
00064         if (!c->radius)
00065             continue;
00066 
00067         /* use at least 12 verts, more for larger coronas */
00068         verts = 12 + c->radius / 8;
00069 
00070         memcpy(&r_state.color_array[0], c->color, sizeof(vec3_t));
00071         r_state.color_array[3] = 1.0f; /* set origin color */
00072 
00073         /* and the corner colors */
00074         memset(&r_state.color_array[4], 0, verts * 2 * sizeof(vec4_t));
00075 
00076         memcpy(&r_state.vertex_array_3d[0], c->org, sizeof(vec3_t));
00077         vertind = 3; /* and the origin */
00078 
00079         for (i = verts; i >= 0; i--) { /* now draw the corners */
00080             const float a = (M_PI * 2 / verts) * i;
00081 
00082             for (j = 0; j < 3; j++)
00083                 v[j] = c->org[j] + r_locals.right[j] * (float) cos(a) * c->radius + r_locals.up[j] * (float) sin(a)
00084                         * c->radius;
00085 
00086             memcpy(&r_state.vertex_array_3d[vertind], v, sizeof(vec3_t));
00087             vertind += 3;
00088         }
00089 
00090         glDrawArrays(GL_TRIANGLE_FAN, 0, vertind / 3);
00091     }
00092 
00093     R_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00094 
00095     R_EnableColorArray(qfalse);
00096 
00097     R_EnableTexture(&texunit_diffuse, qtrue);
00098 
00099     R_Color(NULL);
00100 }

Generated by  doxygen 1.6.2