Tutorial *105*

So you've played Unreal, you walk (or run) up to a surface and you see little grains and marks on it making your jaw drop and continuously drool when you saw it for the first time in July 1998, right? Well it's currently 2002, and MANY MANY games are missing this specialized brand of eye-candy. It's called Detail Textures, and I'll show you how to put 'em into your (TomazQuake only) based engine in 3 ridiculously easy digestable cut-and-paste steps. (the old bumpmapping tutorial was a total nightmare come true btw)

The detail texture code is VERY EARLY at this stage of development... will be improved later. This is the basic detail texture. Any improvements would be gladly appreciated, just email above with the "different code".

Step 1:

First off, we go into gl_warp.c. This is where the special polys are kept at such as envpolys and waterpolys.
Scroll down to the very bottom of the file and add:

// CheapAlert Code - cover your eyes

void EmitDetailPolys (msurface_t *s)


	glpoly_t	*p;

	float		*v;

	int			i, tn;

        vec3_t          vert;

	tn = (int)(host_time * 20)%31;

        glBindTexture (GL_TEXTURE_2D, detailtexture);                    // chp - put in the texture data

        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);        // chp - how the texture is slapped on the polys

        glColor4f (1,1,1,0.3f);                                          // chp - full color, fade off a little

        glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR);                         // chp - this is also known as "modulate blend" in unreal rendering jargon.

	for (p=s->polys ; p ; p=p->next)


                glBegin (GL_POLYGON);                                    // chp - duplicate polys cos i don't know how to multitexture this baby yet

		for (i=0,v=p->verts[0] ; inumverts ; i++, v+=VERTEXSIZE)


                        glTexCoord2f (v[3] * 18, v[4] * 18);             // chp - jam some detail in there, raise these numbers for your viewing pleasure

			glVertex3fv (v);


		glEnd ();




	glColor4f (1,1,1,1);


// CheapAlert code - open your eyes

I'm pretty sure you know what the code above does. ;)

Step 2:

Open gl_rsurf.c, go to R_DrawBrushMTex function and find:


		if (s->flags & SURF_UNDERWATER)


Add this below it:

        EmitDetailPolys(s); // CHP - ranger starts to wear prescription glasses

This will add the detail of course, on all surfaces :)

Step 3:

A detail texture would serve no purpose without a texture, right?
Now we're gonna put the texture in.
Go back into gl_warp.c, find:


// Integer


int		shinytexture;

Below it, add:

int             detailtexture;

Open gl_draw.c, and find:


// Externals


extern void LoadSky_f(void);		// Skybox

extern int	shinytexture;			// Enviroment Mapping

extern int	causticstexture[32];		// Underwater Caustics

extern unsigned char d_15to8table[65536];

Below it, Add:

extern int      detailtexture;                  // chp - Detail Texture

Find these lines:


	// Get the other pics we need


	draw_disc = Draw_PicFromWad ("disc");

	draw_backtile = Draw_PicFromWad ("backtile");

	map_snapshot = loadtextureimage("gfx/mapshots/blankpic", false, false);	// Tomaz - MapShots

	map_snapname = loadtextureimage("gfx/mapshots/blankname", false, false);	// Tomaz - MapShots

	shinytexture = loadtextureimage("textures/shiny", false, true);	// FIXME: Enviroment Mapping


        detailtexture = loadtextureimage("textures/detail", false, true); // CHP - load the Detail Texture

of course, that loads the detail texture.

Compile. Don't forget to extract this detail texture into your "quake/id1/textures/" folder. You'll need it. The texture was derived from GLQuake project's so-called "bump-mapping", which was a total scam IMHO.

Run and enjoy. I will write a tutorial that applies to unchanged engine code sometime.

Not logged in
Sign up