
|
Created By: |
legion |
|
eMail: |
|
|
Difficulty Scale: |
Easy |
One of the things that makes "DLL programming"
such an improvement over QuakeC (and other limited scripted language) is
that the programmer can introduce new graphical features into the game such as
fog. This addition, however, is nowhere near as flexible nor as
"powerful" as having access to the actual graphical 3D engine but one
can add fog in a limited fashion to their mods. The fog tutorial is
exceptionally easy. With a few steps, you can add fog similar to the following:
The first time I have seen fog in Quake II were the
screenshots shown by Rohan of the Navy Seal
II TC. Chemical Existance
also planned to feature fog in their TC before switching to Half-life. I,
myself, did not have the opportunity to see how theirs look liked. These two
TCs are the only two TCs that I am aware of that planned to include fog.
This tutorial is a remake of Rohan's original fog tutorial. It is hoped
that this tutorial is easier to understand than Rohan's original.
The first thing you need to know is that you need to have
an OpenGL v1.1 compliant video card. The nVidia Riva TNT is an example of a
compliant card. If you do not have a compliant card, you won't see any changes
to the game. That is, you won't see any fog. For "pseudo-compliant"
cards such as the 3dfx cards (eg. Voodoo II), you will need the mesa drivers. Download these
mesa drivers and follow the instructions contained within on how to install
them. I do not use these drivers since I do not need a
"pseudo-opengl" card to try out fog. Contact the authors of those
drivers for further instructions.
Ryche also remade Rohan's tutorial to
provide instructions to compile the code using LCC. He also provided the
download link for the mesa drivers, too. I use Visual C++ v6.0 so this tutorial
is based on VC v6.0. I am not familiar with LCC. If you want to use this
tutorial with LCC, you are better off following Ryche's tutorial.
Part 1: Adding OpenGL support
The first thing you need to do is to make sure that your compiler knows that
you want the OpenGL library to be part of your project. The library (like any
libraries) contains compiled code that you can use within your program. This
OpenGL library is simply a collection of code you can use. So when VC compiles
and then links, it would know to include code from the OpenGL library.
·
Step
1: Load your
Quake2 DLL source into Visual C++ as usual.
·
Step
2: From the
menubar, select Project and under project select settings.
·
Step
3: A new Project
Settings window should pop up. You should see a list containing at least
one item--the name of your workspace. Now highlight the name of your
workspace. This is what some people would call the name of your project. This
name is the same name you see on the title bar, right next the words
"Microsoft Visual C++".
·
Step
4: Select the LINK
tab.
·
Step
5: After
selecting the link tab, you should see a box to fill in the names for Object/library
modules:. There should be some names of files already listed in this box
such as kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib.
·
Step
6: At the end of
the above list of file names, add a space then type in the words opengl32.lib.
Click okay.
You have completed adding OpenGL support to your Visual
C++ workspace.
Part 2: Adding OpenGL Fog
After adding OpenGL support to your workspace, you are now ready to use them in
your code.
·
Step
7: Open the file g_main.c.
·
Step
8: Add the OpenGL
headers to g_main.c by adding the following yellow lines of code to the beginning of this file:
#include "g_local.h"
#include
<windows.h>
#include <gl.h>
·
Step
9: Search for the
function called game_export_t *GetGameAPI (game_import_t *import).
·
Step
10: Now go to the
end of this function, you will see a line that says return &globals;.
That is the last line. Above this last line, add the following yellow lines of code:
globals.RunFrame = G_RunFrame;
globals.ServerCommand = ServerCommand;
globals.edict_size = sizeof(edict_t);
{
GLfloat fogColor[] =
{0.0,0.0,1.0,1}; // fog color
// execute OpenGL commands
glEnable (GL_FOG); // turn on fog, otherwise you
won't see any
glFogi (GL_FOG_MODE, GL_EXP2); // Fog fade using exponential
function
glFogfv (GL_FOG_COLOR,
fogColor); // Set the fog color
glFogf (GL_FOG_DENSITY,
0.0020); // Set the density, don't make it too high.
glHint (GL_FOG_HINT,
GL_NICEST); // ROS says Set default calculation mode
}
return &globals;
·
Step
11: Compile
the project. You should see fog in your levels now.
Fog is a graphical feature. This means that fog needs to
be "drawn" on the screen. All the "drawing" is performed by
Quake2.exe. Since you are adding fog to the game code and not to the
quake2.exe itself, you need to make sure that the fog code is executed every
frame. Otherwise, when quake2.exe "draws" another frame it will
"overwrite" any fog in the previous frame and "erase" it.
You can add the fog code snippet anywhere in your mod as long as it is called
every frame.