static void EmitSkyPolys (msurface_t *fa)
{
	glpoly_t	*p;
	float		*v;
	int		i;
	float		s, t;
	vec3_t		dir;
	float		length;

	for (p = fa->polys ; p ; p = p->next)
	{
		glBegin_fp (GL_POLYGON);
		for (i = 0, v = p->verts[0]; i < p->numverts; i++, v += VERTEXSIZE)
		{
			VectorSubtract (v, r_origin, dir);
			dir[2] *= 3;	// flatten the sphere

			length = dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2];
			length = sqrt (length);
			length = 6*63/length;

			dir[0] *= length;
			dir[1] *= length;

			s = (speedscale + dir[0]) * (1.0/128);
			t = (speedscale + dir[1]) * (1.0/128);

			glTexCoord2f_fp (s, t);
			glVertex3fv_fp (v);
		}
		glEnd_fp ();
	}
}
Beispiel #2
0
void R_DrawParticles (void)
{
	int		i, color;
	particle_t	*p;
	float		scale;
#define	SCALE_BASE	((p->type == pt_snow) ? p->count/10 : 1)

	GL_Bind(particletexture);
	glEnable_fp (GL_BLEND);
	glTexEnvf_fp(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	glBegin_fp (GL_TRIANGLES);

	VectorScale (vup, 1.5, r_pup);
	VectorScale (vright, 1.5, r_pright);

	for (p = active_particles ; p ; p = p->next)
	{
		// hack a scale up to keep particles from disapearing
		scale = (p->org[0] - r_origin[0])*vpn[0] +
			(p->org[1] - r_origin[1])*vpn[1] +
			(p->org[2] - r_origin[2])*vpn[2];
		if (scale < 20)
			scale = SCALE_BASE;
		else
			scale = SCALE_BASE + scale * 0.004;

	/* clamp color to 0-511: particle->type 10 and 11 (pt_c_explode
	 * and pt_c_explode2, e.g. Crusader's ice particles hitting a
	 * wall) lead to negative values, because R_UpdateParticles ()
	 * decrements their color against time. */
		color = ((int)p->color) & 0x01ff;
		if (color < 256)
			glColor3ubv_fp ((byte *)&d_8to24table[color]);
		else
			glColor4ubv_fp ((byte *)&d_8to24TranslucentTable[color-256]);

		// setup texture coordinates
		i = 0;
		if (p->type == pt_snow)
		{
			if (p->count >= 69)
				i = 3;	// happy snow!
			else if (p->count >= 40)
				i = 2;
			else if (p->count >= 30)
				i = 1;
		}

		glTexCoord2fv_fp (ptex_coord[i][0]);
		glVertex3fv_fp (p->org);
		glTexCoord2fv_fp (ptex_coord[i][1]);
		glVertex3f_fp (p->org[0] + r_pup[0]*scale, p->org[1] + r_pup[1]*scale, p->org[2] + r_pup[2]*scale);
		glTexCoord2fv_fp (ptex_coord[i][2]);
		glVertex3f_fp (p->org[0] + r_pright[0]*scale, p->org[1] + r_pright[1]*scale, p->org[2] + r_pright[2]*scale);
	}

	glEnd_fp ();
	glDisable_fp (GL_BLEND);
	glTexEnvf_fp(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
}
/*
=============
EmitSkyPolys
=============
*/
static void EmitSkyPolysMulti (msurface_t *fa)
{
	glpoly_t	*p;
	float		*v;
	int		i;
	float	s, ss, t, tt;
	vec3_t		dir;
	float		length;

	glTexEnvf_fp(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	GL_Bind (solidskytexture);

	glActiveTextureARB_fp (GL_TEXTURE1_ARB);
	glTexEnvf_fp(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
	glEnable_fp(GL_TEXTURE_2D);
	GL_Bind (alphaskytexture);

	for (p = fa->polys ; p ; p = p->next)
	{
		glBegin_fp (GL_POLYGON);
		for (i = 0, v = p->verts[0]; i < p->numverts; i++, v += VERTEXSIZE)
		{
			VectorSubtract (v, r_origin, dir);
			dir[2] *= 3;	// flatten the sphere

			length = dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2];
			length = sqrt (length);
			length = 6*63/length;

			dir[0] *= length;
			dir[1] *= length;

			s = (realtime*8 + dir[0]) * (1.0/128);
			t = (realtime*8 + dir[1]) * (1.0/128);

			ss = (realtime*16 + dir[0]) * (1.0/128);
			tt = (realtime*16 + dir[1]) * (1.0/128);

			glMultiTexCoord2fARB_fp (GL_TEXTURE0_ARB, s, t);
			glMultiTexCoord2fARB_fp (GL_TEXTURE1_ARB, ss, tt);
			glVertex3fv_fp (v);
		}
		glEnd_fp ();
	}

	glDisable_fp(GL_TEXTURE_2D);
	glActiveTextureARB_fp (GL_TEXTURE0_ARB);
}
/*
=============
EmitWaterPolys

Does a water warp on the pre-fragmented glpoly_t chain
=============
*/
void EmitWaterPolys (msurface_t *fa)
{
	glpoly_t	*p;
	float		*v;
	int			i;
	float		s, t, os, ot;
	vec3_t		nv;	// waterripple

	if (gl_waterripple.value < 0)
		gl_waterripple.value = 0;
	else if (gl_waterripple.value > 10)
		gl_waterripple.value = 10;

	for (p = fa->polys ; p ; p = p->next)
	{
		glBegin_fp (GL_POLYGON);
		for (i = 0, v = p->verts[0]; i < p->numverts; i++, v += VERTEXSIZE)
		{
			os = v[3];
			ot = v[4];

			nv[0] = v[0];
			nv[1] = v[1];
			nv[2] = v[2] + gl_waterripple.value*sin(v[0]*0.05 + realtime)*sin(v[2]*0.05 + realtime);

			s = os + turbsin[(int)((ot*0.125 + realtime) * TURBSCALE) & 255];
			s *= (1.0/64);

			t = ot + turbsin[(int)((os*0.125 + realtime) * TURBSCALE) & 255];
			t *= (1.0/64);

			glTexCoord2f_fp (s, t);
			//glVertex3fv_fp (v);
			glVertex3fv_fp (nv);
		}
		glEnd_fp ();
	}
}
void R_DrawSkyBox (void)
{
	int		i;

#if 0
	glEnable_fp (GL_BLEND);
	glTexEnvf_fp(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	glColor4f_fp (1,1,1,0.5);
	glDisable_fp (GL_DEPTH_TEST);
#endif
	for (i = 0; i < 6; i++)
	{
		if ( (skymins[0][i] >= skymaxs[0][i]) || (skymins[1][i] >= skymaxs[1][i]) )
			continue;

		GL_Bind(sky_tex[skytexorder[i]]);
#if 0
		skymins[0][i] = -1;
		skymins[1][i] = -1;
		skymaxs[0][i] = 1;
		skymaxs[1][i] = 1;
#endif
		glBegin_fp (GL_QUADS);
		MakeSkyVec (skymins[0][i], skymins[1][i], i);
		MakeSkyVec (skymins[0][i], skymaxs[1][i], i);
		MakeSkyVec (skymaxs[0][i], skymaxs[1][i], i);
		MakeSkyVec (skymaxs[0][i], skymins[1][i], i);
		glEnd_fp ();
	}
#if 0
	glDisable_fp (GL_BLEND);
	glTexEnvf_fp(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glColor4f_fp (1,1,1,0.5);
	glEnable_fp (GL_DEPTH_TEST);
#endif
}
static void DrawSkyPolygon (int nump, vec3_t vecs)
{
	int		i, j;
	vec3_t	v, av;
	float	s, t, dv;
	int		axis;
	float	*vp;

//	c_sky++;
#if 0
	glBegin_fp (GL_POLYGON);
	for (i = 0; i < nump; i++, vecs += 3)
	{
		VectorAdd(vecs, r_origin, v);
		glVertex3fv_fp (v);
	}
	glEnd_fp();
	return;
#endif
	// decide which face it maps to
	VectorClear (v);
	for (i = 0, vp = vecs; i < nump; i++, vp += 3)
	{
		VectorAdd (vp, v, v);
	}
	av[0] = fabs(v[0]);
	av[1] = fabs(v[1]);
	av[2] = fabs(v[2]);
	if (av[0] > av[1] && av[0] > av[2])
	{
		if (v[0] < 0)
			axis = 1;
		else
			axis = 0;
	}
	else if (av[1] > av[2] && av[1] > av[0])
	{
		if (v[1] < 0)
			axis = 3;
		else
			axis = 2;
	}
	else
	{
		if (v[2] < 0)
			axis = 5;
		else
			axis = 4;
	}

	// project new texture coords
	for (i = 0; i < nump; i++, vecs += 3)
	{
		j = vec_to_st[axis][2];
		if (j > 0)
			dv = vecs[j - 1];
		else
			dv = -vecs[-j - 1];

		j = vec_to_st[axis][0];
		if (j < 0)
			s = -vecs[-j -1] / dv;
		else
			s = vecs[j-1] / dv;

		j = vec_to_st[axis][1];
		if (j < 0)
			t = -vecs[-j -1] / dv;
		else
			t = vecs[j-1] / dv;

		if (s < skymins[0][axis])
			skymins[0][axis] = s;
		if (t < skymins[1][axis])
			skymins[1][axis] = t;
		if (s > skymaxs[0][axis])
			skymaxs[0][axis] = s;
		if (t > skymaxs[1][axis])
			skymaxs[1][axis] = t;
	}
}