
TGA - PCX
Texture Loading in Software Mode
|
Copyright
info |
|
All
code in this tutorial is protected by the [GPL License]. |
|
Tutorial
by: High Trigger |
||||||||||||||||||||||||||||||
|
Mailto: webchallenge2@hotmail.com This is my
first tutorial on Quake 2. It will map a 24 bit image into the Quake2 engine
memory. I will work on
optimizing my mipmap code, or replace it. First we need
to enable Quake2 to convert from 24 bit per pixel TGAs to 8 bit per pixel
textures images to use, to do so, Quake2 have a table named 16to8.dat having
a link to each of the color palette that quake2 must use for that color. Note that each
color contained in the current palette used by the server have benn
reconverted to 32 bit for display. But that's another story... ;) This table is
already used in GL mode and is just so easy to import in sofware mode. CODE PART : We first have
to modify the color info maintained in Quake2 this is done in the swstate_s
struct. in r_local.h
change the following:
Now we need
this table to be loaded into the game so we need to load pics/16to8.dat into
the d_16to8table, r_image.c is used for image file loading / handling. So in
r_image.c find the function: void R_InitImages (void), and make it look like
this :
Good, now add
the folowing to r_image.c, just on top of
Insert the
folowing function:
This is a mere
copy from GL_BuildPalettedTexture it translate and write the new texture in
paletted_texture ("scaled" is the original). Compile the
project. Ok, so now we
need to specify that textures may need to be converted before being used. Be carefull
there's two of these function : *GL_LoadPic, one for software mode one for GL
mode. So in R_IMAGE.C find :
Change it to :
We added
"int bits" like in the GL version that is in gl_image. Remember
that we want to use both TGA and 8 bit PCX.
add these var
types to the function :
And after :
Add :
The remaining
code will be :
Ok the hardest
part is done. Compile the project. Now still in r_image.c we go in the
function called : image_t *R_FindImage, and modify the condition where a PCX
wants to load to make it look like this :
Now the
condition for the tga :
Compile the
project. Now be sure you have your textures as 8 bit pcx or 24 bit tga in the
game directory and place them in textures/tga and/or textures/pcx. I'm using
different dirs but you can do what you want. Go into
r_model.c and find the function Mod_LoadTexinfo, theres a line that specify
the file to load. Actually its a .wal file. Make it point to your tga or pcx
files.
Replace it by
:
You're set ! Remember to
leave the .wal file where they belong since they are used by map editors as a
reference to the directory structure at compile time. But once the
map is compiled .wal are not needed at run time. High
Trigger |
Tutorial Originally found at: