Tutorial *27*

First of all sorry for my bad english.
In this tutorial you will see how to add fog effect to "ref_gl"

Ok, open the "REF_GL" Project, and go into "gl_local.h", find the line that says :



   extern  cvar_t  *gl_lockpvs;

And paste this below it :



//========== Engine Fog =================

extern  cvar_t  *gl_fogenable;  // Enable

extern  cvar_t  *gl_fogred;     // Red

extern  cvar_t  *gl_foggreen;   // Green

extern  cvar_t  *gl_fogblue;    // Blue

extern  cvar_t  *gl_fogstart;   // Start

extern  cvar_t  *gl_fogend;     // End

extern  cvar_t  *gl_fogdensity; // Density

//============== End =====================

Now open "gl_rmain.c file, go to the line :



cvar_t	*gl_lockpvs;

And paste this below it :



//========= Engine Fog ==============

cvar_t  *gl_fogenable;     // Enable

cvar_t  *gl_fogred;        // Red

cvar_t  *gl_foggreen;      // Green

cvar_t  *gl_fogblue;       // Blue

cvar_t  *gl_fogstart;      // Start

cvar_t  *gl_fogend;        // End

cvar_t  *gl_fogdensity;    // Density

//============ End ===================

Now still in the same file go to the "R_RenderView" function. This is where the all Fog code is. At the begining of the function paste this :



   vec3_t		colors;	// Fog

And now go to the bottom of this function, until you see this :


	if (r_speeds->value)

	{

		ri.Con_Printf (PRINT_ALL, "%4i wpoly %4i epoly %i tex %i lmaps\n",

			c_brush_polys,

			c_alias_polys,

			c_visible_textures,

			c_visible_lightmaps);

	}

Right after it paste this code :



//===================== Engine Fog ============================

	qglDisable(GL_FOG);



	if (gl_fogenable->value)

	{

		qglFogi(GL_FOG_MODE, GL_LINEAR);

		colors[0] = gl_fogred->value;

		colors[1] = gl_foggreen->value;

		colors[2] = gl_fogblue->value;

		qglFogfv(GL_FOG_COLOR, colors);

		qglFogf(GL_FOG_START, gl_fogstart->value);

		qglFogf(GL_FOG_END, gl_fogend->value);

		qglFogf(GL_FOG_DENSITY, gl_fogdensity->value);

		qglEnable(GL_FOG);

	}

	else

	{

    qglDisable(GL_FOG);

}

//====================== End ==========================

And we are allmost done. All we need is to go to the line that look like this :



   gl_3dlabs_broken = ri.Cvar_Get( "gl_3dlabs_broken", "1", CVAR_ARCHIVE );

And paste this below :



//========================== Engine Fog ============================



    gl_fogenable  = ri.Cvar_Get( "gl_fogenable", "1", 0 );

    gl_fogstart   = ri.Cvar_Get( "gl_fogstart", "50.0", 0 );

    gl_fogend     = ri.Cvar_Get( "gl_fogend", "800.0", 0 );

    gl_fogdensity = ri.Cvar_Get( "gl_fogdensity", "0.8", 0 );

    gl_fogred     = ri.Cvar_Get( "gl_fogred","0.6", 0 );

    gl_foggreen   = ri.Cvar_Get( "gl_foggreen","0.5", 0 );

    gl_fogblue    = ri.Cvar_Get( "gl_fogblue","0.4", 0 );



//============================= End ================================

Ok now its all. Now you can have a fog, and controll it from console. How to controll it i think you know :)
If you hawe any qestions, please mail me :)



 
Not logged in
Sign up
Login:
Passwd: