Tutorial *40*

Hi there, I’m Convulsion-X and this is the first tutorial I’ve ever written so please don’t scream at me if you don’t understand it. You can instead e-mail me at [email protected] and I will try to fix it. Anyway, I plan on teaching you how to get the Quake II engine to load 32-bit targas instead of those crappy 8-bit PCX files. It’s only a few lines of code and really makes a difference in the way the game looks.

First we will get the engine to load TGA’s instead of Wals. (Note: This is really just MR. G’s tutorial. I included it in here just to make things complete rather than having additional HTML files or whatever)

Open up the QII src and go into the ref_gl part. Open up GL_Model.c and go down to Mod_LoadTexInfo. This contains all of the information for loading textures onto a BSP surface. Find this line:



		out->next = NULL;

		Com_sprintf (name, sizeof(name), "textures/%s.wal", in->texture);

		out->image = GL_FindImage (name, it_wall);

Now change it to this:



		out->next = NULL;

		Com_sprintf (name, sizeof(name), "textures/%s.tga", in->texture);

		out->image = GL_FindImage (name, it_wall);

		if (!out)

		{

			Com_sprintf(name, sizeof(name), “textures/%s.wal”, in->texture);

			out->image = GL_FindImage (name, it_wall);

		}

This will check to see if there is a targa in the textures folder for the .wal assigned to it. If not then it just loads the wal.

Now onto models. This is from a tutorial by Korax. Again, just figured it’d be easier for you if all the information was in one spot.

Anyway you should still have gl_model.c open. Go down to R_RegisterModel. Underneath



	dmdl_t		*pheader;

Add:



	char		md2skin[MAX_PATH];

Then find:



	for (i=0 ; inum_skins ; i++)

		mod->skins[i] = GL_FindImage ((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME, it_skin);

And change it to:



	for (i=0 ; inum_skins ; i++)

	{

		COM_StripExtension((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME, md2skin);

		strcat(md2skin, ".tga");

		mod->skins[i] = GL_FindImage (md2skin, it_skin);

		if(!mod->skins[i])

			mod->skins[i] = GL_FindImage ((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME, it_skin);

	}

Once again, this will search for the targa by the name of the PCX assigned to it by the model. If it doesn’t find it, it will load the PCX.

Now to load TGAs instead of menu items and statusbar crap

Go to gl_draw.c and find the function: image_t *Draw_FindPic (char name)

Find the line that reads:



	Com_sprintf (fullname, sizeof(fullname), "pics/%s.pcx", name);

	gl = GL_FindImage (fullname, it_pic);

And change it to:



	Com_sprintf (fullname, sizeof(fullname), "pics/%s.tga", name);

	gl = GL_FindImage (fullname, it_pic);

	if (!gl)

	{

		Com_sprintf (fullname, sizeof(fullname), "pics/%s.pcx", name);

        	gl = GL_FindImage (fullname, it_pic);

        }

Now anytime the Draw_FindPic function is called it will check for a TGA before loading the PCX.

Now, getting the sprites to load TGAs instead of PCXs.

Open gl_model.c again and go back to R_RegisterModel, under where you wrote char md2skin[MAX_PATH] before write:



char	sp2skin[MAX_PATH];

change:


	for (i=0 ; inumframes ; i++)

		mod->skins[i] = GL_FindImage (sprout->frames[i].name, it_sprite);

to:



	for (i=0 ; inumframes ; i++)

	{

		Com_StripExtension (sprout->frames[i].name, sp2skin[MAX_PATH]);

		strcat (sp2skin, “.tga”);

        mod->skins[i] = GL_FindImage (sp2skin, it_sprite);

        if (!mod_skins[i])

        mod->skins[i] = GL_FindImage (sprout->frames[i].name, it_sprite);

	}

And that should be about it. I was going to add how to change the particle system to a targa too, but it sort of slows down the engine and it’s a lot more code. Maybe if I get enough e-mails asking how to do it or something I will. For those that want to try on their own you have to get the engine to draw a square instead of a triangle and change the texture coordinates so that it covers the whole thing square instead of a little section of it. Then in GL_Part.c at the gl_findimage part replace the call for the dot drawn above with the texture of your choice.
Peace!



 
Not logged in
Sign up
Login:
Passwd: