Exemple #1
0
void RSky_BeginFrame (void)
{
	glmatrix skymatrix;

	GL_LoadIdentity (&skymatrix);

	GL_RotateMatrix (&skymatrix, -90, 1, 0, 0);
	GL_RotateMatrix (&skymatrix, 90, 0, 0, 1);

	GL_RotateMatrix (&skymatrix, r_newrefdef.time * skyrotate, skyaxis[0], skyaxis[2], skyaxis[1]);
	GL_TranslateMatrix (&skymatrix, -r_origin[0], -r_origin[1], -r_origin[2]);

	glProgramUniformMatrix4fv (gl_skycubeprog, u_skytexturematrix, 1, GL_FALSE, skymatrix.m[0]);
}
/*
 ==================
 GL_Setup3D

 TODO: time is messed up
 ==================
*/
void GL_Setup3D (int time){

	double	clipPlane[4];

	QGL_LogPrintf("---------- RB_Setup3D ----------\n");

	backEnd.projection2D = false;

	backEnd.time = time;
	backEnd.floatTime = MS2SEC(Sys_Milliseconds());

	backEnd.viewport.x = backEnd.viewParms.viewport.x;
	backEnd.viewport.y = backEnd.viewParms.viewport.y;
	backEnd.viewport.width = backEnd.viewParms.viewport.width;
	backEnd.viewport.height = backEnd.viewParms.viewport.height;

	backEnd.scissor.x = backEnd.viewParms.scissor.x;
	backEnd.scissor.y = backEnd.viewParms.scissor.y;
	backEnd.scissor.width = backEnd.viewParms.scissor.width;
	backEnd.scissor.height = backEnd.viewParms.scissor.height;

	backEnd.coordScale[0] = 1.0f / backEnd.viewport.width;
	backEnd.coordScale[1] = 1.0f / backEnd.viewport.height;

	backEnd.coordBias[0] = -backEnd.viewport.x * backEnd.coordScale[0];
	backEnd.coordBias[1] = -backEnd.viewport.y * backEnd.coordScale[1];

	backEnd.depthFilling = false;
	backEnd.debugRendering = false;

	backEnd.currentColorCaptured = SORT_BAD;
	backEnd.currentDepthCaptured = false;

	// Set up the viewport
	GL_Viewport(backEnd.viewport);

	// Set up the scissor
	GL_Scissor(backEnd.viewport);

	// Set up the depth bounds
	if (glConfig.depthBoundsTestAvailable)
		GL_DepthBounds(0.0f, 1.0f);

	// Set the projection matrix
	GL_LoadMatrix(GL_PROJECTION, backEnd.viewParms.projectionMatrix);

	// Set the modelview matrix
	GL_LoadIdentity(GL_MODELVIEW);

	// Set the GL state
	GL_PolygonMode(GL_FILL);

	GL_Disable(GL_CULL_FACE);
	GL_Disable(GL_POLYGON_OFFSET_FILL);
	GL_Disable(GL_BLEND);
	GL_Disable(GL_ALPHA_TEST);
	GL_Disable(GL_DEPTH_TEST);
	GL_Disable(GL_STENCIL_TEST);

	GL_DepthRange(0.0f, 1.0f);

	GL_ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
	GL_DepthMask(GL_TRUE);
	GL_StencilMask(255);

	// Enable the clip plane if needed
	if (backEnd.viewParms.viewType != VIEW_MIRROR)
		qglDisable(GL_CLIP_PLANE0);
	else {
		clipPlane[0] = -DotProduct(backEnd.viewParms.axis[1], backEnd.viewParms.clipPlane.normal);
		clipPlane[1] = DotProduct(backEnd.viewParms.axis[2], backEnd.viewParms.clipPlane.normal);
		clipPlane[2] = -DotProduct(backEnd.viewParms.axis[0], backEnd.viewParms.clipPlane.normal);
		clipPlane[3] = DotProduct(backEnd.viewParms.origin, backEnd.viewParms.clipPlane.normal) - backEnd.viewParms.clipPlane.dist;

		qglEnable(GL_CLIP_PLANE0);
		qglClipPlane(GL_CLIP_PLANE0, clipPlane);
	}

	// Enable multisampling if available
	if (glConfig.multiSamples > 1)
		qglEnable(GL_MULTISAMPLE);

	// Clear the buffers
	qglClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	qglClearDepth(1.0f);
	qglClearStencil(0);

	if (backEnd.viewParms.primaryView)
		qglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	else
		qglClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	// Check for errors
	if (!r_ignoreGLErrors->integerValue)
		GL_CheckForErrors();

	QGL_LogPrintf("--------------------\n");
}
/*
 ==================
 GL_Setup2D

 TODO: time is messed up
 ==================
*/
void GL_Setup2D (int time){

	mat4_t	projectionMatrix = {2.0f / backEnd.cropWidth, 0.0f, 0.0f, 0.0f, 0.0f, -2.0f / backEnd.cropHeight, 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 0.0f, -1.0f, 1.0f, -1.0f, 1.0f};

	QGL_LogPrintf("---------- RB_Setup2D ----------\n");

	backEnd.projection2D = true;

	backEnd.time = time;
	backEnd.floatTime = MS2SEC(Sys_Milliseconds());

	backEnd.viewport.x = 0;
	backEnd.viewport.y = 0;
	backEnd.viewport.width = backEnd.cropWidth;
	backEnd.viewport.height = backEnd.cropHeight;

	backEnd.scissor.x = 0;
	backEnd.scissor.y = 0;
	backEnd.scissor.width = backEnd.cropWidth;
	backEnd.scissor.height = backEnd.cropHeight;

	backEnd.coordScale[0] = 1.0f / backEnd.viewport.width;
	backEnd.coordScale[1] = 1.0f / backEnd.viewport.height;

	backEnd.coordBias[0] = -backEnd.viewport.x * backEnd.coordScale[0];
	backEnd.coordBias[1] = -backEnd.viewport.y * backEnd.coordScale[1];

	backEnd.depthFilling = false;
	backEnd.debugRendering = false;

	backEnd.currentColorCaptured = SORT_BAD;
	backEnd.currentDepthCaptured = false;

	// Set up the viewport
	GL_Viewport(backEnd.viewport);

	// Set up the scissor
	GL_Scissor(backEnd.viewport);

	// Set up the depth bounds
	if (glConfig.depthBoundsTestAvailable)
		GL_DepthBounds(0.0f, 1.0f);

	// Set the projection matrix
	GL_LoadMatrix(GL_PROJECTION, projectionMatrix);

	// Set the modelview matrix
	GL_LoadIdentity(GL_MODELVIEW);

	// Set the GL state
	GL_PolygonMode(GL_FILL);

	GL_Disable(GL_CULL_FACE);
	GL_Disable(GL_POLYGON_OFFSET_FILL);
	GL_Disable(GL_BLEND);
	GL_Disable(GL_ALPHA_TEST);
	GL_Disable(GL_DEPTH_TEST);
	GL_Disable(GL_STENCIL_TEST);

	GL_DepthRange(0.0f, 1.0f);

	GL_ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
	GL_DepthMask(GL_FALSE);
	GL_StencilMask(255);

	// Disable the clip plane
	qglDisable(GL_CLIP_PLANE0);

	// Disable multisampling if available
	if (glConfig.multiSamples > 1)
		qglDisable(GL_MULTISAMPLE);

	// Check for errors
	if (!r_ignoreGLErrors->integerValue)
		GL_CheckForErrors();

	QGL_LogPrintf("--------------------\n");
}
Exemple #4
0
/*
=================
R_DrawAliasModel
=================
*/
void R_DrawAliasModel (entity_t *e)
{
	int			i;
	dmdl_t		*hdr;
	float		an;
	vec3_t		bbox[8];
	image_t		*skin;
	float		lightspot[3];

	if (!(e->flags & RF_WEAPONMODEL))
	{
		if (R_CullAliasModel (bbox, e))
			return;
	}

	if (e->flags & RF_WEAPONMODEL)
	{
		if (r_lefthand->value == 2)
			return;
	}

	hdr = (dmdl_t *) e->model->extradata;

	if (e->flags & (RF_SHELL_GREEN | RF_SHELL_RED | RF_SHELL_BLUE))
	{
		VectorClear (gl_meshuboupdate.shadelight);

		if (e->flags & RF_SHELL_RED) gl_meshuboupdate.shadelight[0] = 1.0;
		if (e->flags & RF_SHELL_GREEN) gl_meshuboupdate.shadelight[1] = 1.0;
		if (e->flags & RF_SHELL_BLUE) gl_meshuboupdate.shadelight[2] = 1.0;
	}
	else if (e->flags & RF_FULLBRIGHT)
	{
		gl_meshuboupdate.shadelight[0] = 1.0;
		gl_meshuboupdate.shadelight[1] = 1.0;
		gl_meshuboupdate.shadelight[2] = 1.0;
	}
	else
	{
		dlight_t *l;
		int i;

		// grab static lighting from lightmap
		R_LightPoint (e->currorigin, gl_meshuboupdate.shadelight, lightspot);

		// grab dynamic lighting
		glProgramUniform1i (gl_meshprog, u_meshMaxLights, r_newrefdef.num_dlights);
		glProgramUniform3fv (gl_meshprog, u_meshEntOrig, 1, e->currorigin);
		for (i = 0, l = r_newrefdef.dlights; i < r_newrefdef.num_dlights; i++, l++)
		{
			glProgramUniform3fv (gl_meshprog, u_meshLightPos[i], 1, l->origin);
			glProgramUniform3fv (gl_meshprog, u_meshLightColor[i], 1, l->color);
			glProgramUniform1f (gl_meshprog, u_meshLightAtten[i], l->radius);
		}

		// player lighting hack for communication back to server
		// big hack!
		if (e->flags & RF_WEAPONMODEL)
		{
			// pick the greatest component, which should be the same
			// as the mono value returned by software
			if (gl_meshuboupdate.shadelight[0] > gl_meshuboupdate.shadelight[1])
			{
				if (gl_meshuboupdate.shadelight[0] > gl_meshuboupdate.shadelight[2])
					r_lightlevel->value = 150 * gl_meshuboupdate.shadelight[0];
				else r_lightlevel->value = 150 * gl_meshuboupdate.shadelight[2];
			}
			else
			{
				if (gl_meshuboupdate.shadelight[1] > gl_meshuboupdate.shadelight[2])
					r_lightlevel->value = 150 * gl_meshuboupdate.shadelight[1];
				else r_lightlevel->value = 150 * gl_meshuboupdate.shadelight[2];
			}
		}
	}

	if (e->flags & RF_MINLIGHT)
	{
		for (i = 0; i < 3; i++)
		{
			if (gl_meshuboupdate.shadelight[i] > 0.1)
				break;
		}

		if (i == 3)
		{
			gl_meshuboupdate.shadelight[0] = 0.1;
			gl_meshuboupdate.shadelight[1] = 0.1;
			gl_meshuboupdate.shadelight[2] = 0.1;
		}
	}

	if (e->flags & RF_GLOW)
	{
		// bonus items will pulse with time
		float	scale;
		float	min;

		scale = 0.1 * sin (r_newrefdef.time * 7);

		for (i = 0; i < 3; i++)
		{
			min = gl_meshuboupdate.shadelight[i] * 0.8;
			gl_meshuboupdate.shadelight[i] += scale;

			if (gl_meshuboupdate.shadelight[i] < min)
				gl_meshuboupdate.shadelight[i] = min;
		}
	}

	an = e->angles[1] / 180 * M_PI;
	Q_sincos (-an, &gl_meshuboupdate.shadevector[1], &gl_meshuboupdate.shadevector[0]);
	gl_meshuboupdate.shadevector[2] = 1;
	VectorNormalize (gl_meshuboupdate.shadevector);

	// locate the proper data
	c_alias_polys += hdr->num_tris;

	// draw all the triangles
	if (e->flags & RF_DEPTHHACK) // hack the depth range to prevent view model from poking into walls
		glDepthRange (gldepthmin, gldepthmin + 0.3 * (gldepthmax - gldepthmin));

	if ((e->flags & RF_WEAPONMODEL) && (r_lefthand->value == 1.0F))
	{
		glmatrix gunmatrix;

		GL_LoadIdentity (&gunmatrix);
		GL_ScaleMatrix (&gunmatrix, -1, 1, 1);
		GL_PerspectiveMatrix (&gunmatrix, r_newrefdef.fov_y, (float) r_newrefdef.width / r_newrefdef.height);

		// eval a new mvp for left-handedness
		GL_LoadMatrix (&gl_meshuboupdate.localMatrix, &r_worldmatrix);
		GL_MultMatrix (&gl_meshuboupdate.localMatrix, &gl_meshuboupdate.localMatrix, &gunmatrix);

		glCullFace (GL_BACK);
	}
	else
		GL_LoadMatrix (&gl_meshuboupdate.localMatrix, &r_mvpmatrix);

	GL_TranslateMatrix (&gl_meshuboupdate.localMatrix, e->currorigin[0], e->currorigin[1], e->currorigin[2]);
	GL_RotateMatrix (&gl_meshuboupdate.localMatrix, e->angles[1], 0, 0, 1);
	GL_RotateMatrix (&gl_meshuboupdate.localMatrix, e->angles[0], 0, 1, 0);
	GL_RotateMatrix (&gl_meshuboupdate.localMatrix, -e->angles[2], 1, 0, 0);

	// select skin
	if (e->skin)
		skin = e->skin;	// custom player skin
	else
	{
		if (e->skinnum >= MAX_MD2SKINS)
			skin = e->model->skins[0];
		else
		{
			skin = e->model->skins[e->skinnum];

			if (!skin)
				skin = e->model->skins[0];
		}
	}

	if (!skin)
		skin = r_notexture;	// fallback...

	GL_BindTexture (GL_TEXTURE0, GL_TEXTURE_2D, r_modelsampler, skin->texnum);

	if ((e->currframe >= hdr->num_frames) || (e->currframe < 0))
	{
		VID_Printf (PRINT_ALL, S_COLOR_RED "R_DrawAliasModel %s: no such frame %d\n", e->model->name, e->currframe);
		e->currframe = 0;
		e->lastframe = 0;
	}

	if ((e->lastframe >= hdr->num_frames) || (e->lastframe < 0))
	{
		VID_Printf (PRINT_ALL, S_COLOR_RED "R_DrawAliasModel %s: no such oldframe %d\n", e->model->name, e->lastframe);
		e->currframe = 0;
		e->lastframe = 0;
	}

	if (!r_lerpmodels->value)
		e->backlerp = 0;

	GL_DrawAliasFrameLerp (e, hdr, e->backlerp);

	if ((e->flags & RF_WEAPONMODEL) && (r_lefthand->value == 1.0F))
	{
		glCullFace (GL_FRONT);
	}

	if (e->flags & RF_DEPTHHACK)
		glDepthRange (gldepthmin, gldepthmax);
}