Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

main.cpp File Reference

#include <windows.h>
#include "shared.h"
#include "general.h"
#include "listnode.h"
#include "locmath.h"
#include "vector.h"
#include "vertex.h"
#include "quat.h"
#include "matrix.h"
#include "texture.h"
#include "polygon.h"
#include "tll.h"
#include "plane.h"
#include "object.h"
#include "camera.h"
#include "light.h"
#include "collision.h"
#include "glfont.h"
#include "bspline.h"
#include "bsp.h"
#include "portal.h"
#include "pvs.h"
#include "tga.h"
#include "lightmap.h"
#include "winfuncs.h"
#include "console.h"
#include "log.h"
#include "bass.h"
#include "sound.h"
#include "bullet.h"
#include "decal.h"
#include "particle.h"
#include "brush.h"
#include "csg.h"
#include "mmgr.h"
#include "resource.rh"

Go to the source code of this file.

Functions

int InitGL (int Width, int Height)
void ReSizeGLScene (int Width, int Height)
void DrawGLScene (void)
LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE, LPSTR, int)

Variables

ConsoleWindow Console
HGLRC hRC
HDC hDC
HWND hWnd
HINSTANCE g_hInst
RECT screen
PAINTSTRUCT ps
char AppDirectory [MAX_PATH]
float ApplicationStartTime
float pi = 3.141592
float radian = pi / 180
float epsilon = 0.05
bool key [256]
bool released_key [256]
int currentCamera = 0
int numCameras = 4
float step = 30.0
float lasttime
float multiplier
const int average = 10
float lastmultiplier [average]
int fps
int GL_LIGHT [8] = {GL_LIGHT0, GL_LIGHT1, GL_LIGHT2, GL_LIGHT3, GL_LIGHT4, GL_LIGHT5, GL_LIGHT6, GL_LIGHT7}
int currentLight = 0
int numLights = 0
PLANE frustum [6]
int numVertices = 37
VERTEXvertex = new VERTEX[numVertices]
int numWorldPolygons = 58
POLYGONworldPolygons = new POLYGON[numWorldPolygons]
POLYGONbspPolygons = new POLYGON[numWorldPolygons]
TEXTUREtexture = new TEXTURE[11]
CAMERAcamera = new CAMERA[numCameras + 1]
CAMERA LastCam
int maxDecals = 100
DECAL muzzleflashdecal
DECAL impactflashdecal
LIGHTlight = new LIGHT[numLights + 1]
float lightColor [3] = {1.0, 1.0, 1.0}
HWND hWndStartDlg
int DialogInUse = 0
char szText [BUFFER_SIZE]
GLFONT myFont
float Min_X
float Min_Y
float Min_Z
float Max_X
float Max_Y
float Max_Z
int numleavesvisible = 0
int showportals = 0
int numlistleaves = 0
int numlistpartitions = 0
int numcurrentportals = 0
int device
BOOL lowqual
int numSamples = 0
int numChannels = 0
LinkedList< SOUND_SAMPLESampleList
LinkedList< SOUND_CHANNELChannelList
int bulletspeed = 0
int bullettype = 1
int numBulletsActive = 0
int numBullets = 50
float shotlast
BULLETbullet = new BULLET[numBullets]
int numleaves = 0
int currentleaf = 0
int numpartitions = 0
bool BuiltBSP = false
BSP_noderoot = new BSP_node
int numBrushes = 3
POLYGONbrushPolygons = new POLYGON[14]
BRUSHBrushSet = NULL
BRUSHBrush = new BRUSH[3]
VERTEXvertex1 = new VERTEX[8]
VERTEXvertex2 = new VERTEX[8]
VERTEXvertex3 = new VERTEX[8]
int numportals = 0
LinkedList< PORTALPortalList
LinkedList< PORTALBrushPortalList
PORTALportal
int numStaticLights = 9
StaticLightstaticlight = new StaticLight[numStaticLights]
int numLightmaps = 0
Lightmaplightmap = new Lightmap[numWorldPolygons]
int visible = 0
int numSplines = 0
int cameraMode = 2
int currentSpline = 0
int lookAtPath = 0
char SplineFileName [MAX_PATH]
SPLINEspline
LinkedList< SPLINESplineList
LinkedList< BSP_nodeLeafList
LinkedList< BSP_nodePartitionList
BSP_nodelistnode
ParticleManager PManager
bool Texturing = 0
bool CSGflag = 0
bool CSGcullface = 1


Function Documentation

void DrawGLScene void   
 

Definition at line 309 of file main.cpp.

References LIGHT::Apply(), CalculatePVS(), channel_gunshot, CheckForCollision(), CountVisibleLeaves(), currentCamera, currentleaf, DrawBrushes(), DrawDecals(), DrawMyText(), DrawSplines(), DrawWorld(), CollisionPacket::eRadius, ExtractFrustum(), FindCurrentLeaf(), numleavesvisible, numLights, numWorldPolygons, OBJECT::Position, CollisionPacket::sourcePoint, ParticleManager::Update(), UpdateBullets(), UpdateChannel(), UpdateListener(), CollisionPacket::velocity, VECTOR::x, VECTOR::y, and VECTOR::z.

Referenced by WinMain(), and WndProc().

00310 {
00311     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00312 
00313     LastCam = camera[currentCamera];
00314     camera[currentCamera].Update();
00315 
00316     CollisionPacket cp;
00317     cp.eRadius.x = 1.0;
00318     cp.eRadius.y = 1.0;
00319     cp.eRadius.z = 1.0;
00320     cp.sourcePoint.x = LastCam.Position.x;
00321     cp.sourcePoint.y = LastCam.Position.y;
00322     cp.sourcePoint.z = LastCam.Position.z;
00323     cp.velocity.x = camera[currentCamera].Position.x - LastCam.Position.x;
00324     cp.velocity.y = camera[currentCamera].Position.y - LastCam.Position.y;
00325     cp.velocity.z = camera[currentCamera].Position.z - LastCam.Position.z;
00326 
00327     CheckForCollision(&camera[currentCamera].Position, numWorldPolygons, worldPolygons, &cp);
00328 
00329     camera[currentCamera].Apply();
00330 
00331     for(int loop = 0; loop <= numLights; loop++)
00332         light[loop].Apply();
00333 
00334     currentleaf = FindCurrentLeaf(camera[currentCamera].Position, root);
00335 
00336     ExtractFrustum();
00337     CalculatePVS(currentleaf);
00338     numleavesvisible = CountVisibleLeaves();
00339 
00340     UpdateListener();
00341     UpdateChannel(channel_gunshot, &camera[currentCamera].Position, NULL, NULL);
00342 
00343     UpdateBullets();
00344 
00345     PManager.Update();
00346 
00347     DrawWorld(root);
00348 
00349     DrawDecals();
00350 
00351     // Draw CSG Brushes
00352     // The function can be found at the end of general.cpp
00353     DrawBrushes();
00354 
00355     DrawSplines(SplineList);           // Required to calculate the camera path
00356 
00357     DrawMyText();              // Draw text last
00358 }

int InitGL int    Width,
int    Height
 

Definition at line 197 of file main.cpp.

References AddPortalsToLeaves(), ApplicationStartTime, BuildBSP(), BuiltBSP, cameraMode, VERTEX::coords, CreateBSPLightmaps(), CreateSounds(), FindTruePortals(), glFontCreate(), InitializeBASS(), InitializeBullets(), BSP_node::leaf, LoadBSPLightmaps(), MakeNodeLists(), MakePortalList(), Max_X, Max_Y, Max_Z, Min_X, Min_Y, Min_Z, BSP_node::nodeid, BSP_node::nodelightmaplist, BSP_node::nodepolylist, BSP_node::numdecals, BSP_node::numpolys, numWorldPolygons, ResetBrushes(), SetGLCamera(), SetGLLighting(), SetGLMaterial(), SetGLProperties(), SetGLTexture(), SetGLWorld(), SetSplines(), SetStaticLights(), DECAL::Size, POLYGON::Vertex, BSP_node::visible, VECTOR::x, VECTOR::y, and VECTOR::z.

Referenced by WinMain().

00198 {
00199     int ReturnValue;
00200     // Seed the random number generator
00201     srand((unsigned)time(NULL));
00202     // Initialize the sound
00203     InitializeBASS();
00204     CreateSounds();
00205     // Set the application start time
00206     ApplicationStartTime = (float)GetTickCount();
00207     // Set the initial camera mode
00208     cameraMode = 0;
00209     // Set the OpenGL state
00210     SetGLProperties();
00211     SetGLMaterial();
00212     SetGLLighting(light);
00213     // Set the camera and splines
00214     SetGLCamera(camera);
00215     SetSplines(SplineList);
00216     // Set the textures
00217     if (!SetGLTexture(texture))
00218         ReturnValue = 0;
00219     else
00220         ReturnValue = 1;
00221 
00222     // Create the font texture
00223     glFontCreate(&myFont, "roman.glf", 600);
00224 
00225     // Initialize the world geometry
00226     SetGLWorld(worldPolygons, texture, vertex);
00227 
00228     // Find the bounding box of the data set
00229     Min_X = worldPolygons[0].Vertex[0].coords.x;
00230     Min_Y = worldPolygons[0].Vertex[0].coords.y;
00231     Min_Z = worldPolygons[0].Vertex[0].coords.z;
00232     Max_X = worldPolygons[0].Vertex[0].coords.x;
00233     Max_Y = worldPolygons[0].Vertex[0].coords.y;
00234     Max_Z = worldPolygons[0].Vertex[0].coords.z;
00235     for (int loop = 0; loop < numWorldPolygons; loop++)
00236     {
00237         for (int i = 0; i < 3; i++)
00238         {
00239             if (worldPolygons[loop].Vertex[i].coords.x < Min_X )
00240                 Min_X = worldPolygons[loop].Vertex[i].coords.x;
00241             if (worldPolygons[loop].Vertex[i].coords.y < Min_Y )
00242                 Min_Y = worldPolygons[loop].Vertex[i].coords.y;
00243             if (worldPolygons[loop].Vertex[i].coords.z < Min_Z )
00244                 Min_Z = worldPolygons[loop].Vertex[i].coords.z;
00245             if (worldPolygons[loop].Vertex[i].coords.x > Max_X )
00246                 Max_X = worldPolygons[loop].Vertex[i].coords.x;
00247             if (worldPolygons[loop].Vertex[i].coords.y > Max_Y )
00248                 Max_Y = worldPolygons[loop].Vertex[i].coords.y;
00249             if (worldPolygons[loop].Vertex[i].coords.z > Max_Z )
00250                 Max_Z = worldPolygons[loop].Vertex[i].coords.z;
00251         }
00252     }
00253 
00254     // BSP initialization
00255     for (int i = 0; i < numWorldPolygons; i++)
00256         bspPolygons[i] = worldPolygons[i];
00257 
00258     root->nodeid = 0;
00259     root->leaf = 0;
00260     root->visible = 0;
00261     root->numpolys = numWorldPolygons;
00262     root->nodepolylist = bspPolygons;
00263     root->nodelightmaplist = lightmap;
00264     root->numdecals = 0;
00265     BuildBSP(root);
00266     BuiltBSP = true;
00267 
00268     // Portal Creation
00269     MakeNodeLists(root);
00270     MakePortalList();
00271     AddPortalsToLeaves(root);
00272     FindTruePortals(root);
00273 
00274     // Initialize static lights
00275     SetStaticLights(staticlight);
00276 
00277     // Create the lightmaps
00278     CreateBSPLightmaps(root);
00279     LoadBSPLightmaps(root);
00280 
00281     // Model Initialization
00282     InitializeBullets();
00283 
00284     // Decal Initialization
00285     muzzleflashdecal.Size = 3;
00286     impactflashdecal.Size = 3;
00287 
00288 /*
00289     // Particle Initialization
00290     VECTOR tempvect(0.0, -10.0, -30);
00291     CreateRomanCandle(tempvect);
00292     tempvect.Set(-10.0, -10.0, -30);
00293     CreateBouncy(tempvect);
00294     tempvect.Set(10.0, -10.0, -30);
00295     CreateBouncy(tempvect);
00296 //*/
00297 
00298     // CSG Brush Initialization
00299     ResetBrushes();
00300 
00301     return ReturnValue;
00302 }

void ReSizeGLScene int    Width,
int    Height
 

Definition at line 304 of file main.cpp.

References SetGLView().

Referenced by WndProc().

00305 {
00306     SetGLView(Width, Height);
00307 }

int WINAPI WinMain HINSTANCE    hInstance,
HINSTANCE   ,
LPSTR   ,
int   
 

Definition at line 541 of file main.cpp.

References DECAL::active, BULLET::active, AppDirectory, ApplicationStartTime, average, cameraMode, channel_gunshot, Console, CSGAddition(), CSGcullface, CSGflag, currentCamera, currentLight, DialogInUse, DrawGLScene(), FALSE, BULLET::flag, g_hInst, GetTimePassed(), hDC, hRC, hWnd, InitGL(), key, lastmultiplier, lasttime, OBJECT::Multiplier, multiplier, numBullets, numBulletsActive, OBJECT::Orientation, BULLET::OriginalPosition, PlayChannel(), OBJECT::Position, BULLET::PreviousPosition, released_key, ResetBrushes(), screen, shotlast, step, Texturing, TRUE, BULLET::VelocityVector, and WndProc().

00545 {
00546     MSG        msg;
00547     g_hInst = hInstance;
00548     GetWindowRect(GetDesktopWindow(), &screen);
00549 
00550     WNDCLASSEX    wc;
00551     wc.cbSize = sizeof(WNDCLASSEX);
00552     wc.style            = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_SAVEBITS;
00553     wc.lpfnWndProc        = (WNDPROC) WndProc;
00554     wc.cbClsExtra        = 0;
00555     wc.cbWndExtra        = 0;
00556     wc.hInstance        = hInstance;
00557     wc.hIcon            = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON));
00558     wc.hIconSm          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON));
00559     wc.hCursor            = LoadCursor(NULL, IDC_ARROW);
00560     wc.hbrBackground    = NULL;
00561     wc.lpszMenuName        = NULL;
00562     wc.lpszClassName    = "OpenGL WinClass";
00563 
00564 
00565     if(!RegisterClassEx(&wc))
00566     {
00567         MessageBox(NULL,"Failed To Register The Window Class.","Error",MB_OK|MB_ICONERROR);
00568         return FALSE;
00569     }
00570 
00571     hWnd = CreateWindowEx(
00572     WS_EX_LEFT,
00573     "OpenGL WinClass",
00574     "OpenGL & Win32 Tutorial No.20",
00575     WS_MAXIMIZE |
00576     WS_CLIPCHILDREN |
00577     WS_CLIPSIBLINGS |
00578     WS_POPUPWINDOW |
00579     WS_VISIBLE,
00580     0, 0,
00581     screen.right, screen.bottom,
00582     NULL,
00583     NULL,
00584     hInstance,
00585     NULL);
00586 
00587     if(!hWnd)
00588     {
00589         MessageBox(NULL,"Window Creation Error.","Error",MB_OK|MB_ICONERROR);
00590         return FALSE;
00591     }
00592 
00593     DEVMODE dmScreenSettings;
00594     memset(&dmScreenSettings, 0, sizeof(DEVMODE));
00595     dmScreenSettings.dmSize        = sizeof(DEVMODE);
00596     dmScreenSettings.dmPelsWidth    = screen.right;
00597     dmScreenSettings.dmPelsHeight    = screen.bottom;
00598     dmScreenSettings.dmFields    = DM_PELSWIDTH | DM_PELSHEIGHT;
00599     ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);
00600 
00601     ShowWindow(hWnd, SW_HIDE);
00602 
00603     GetCurrentDirectory(MAX_PATH, AppDirectory);
00604 
00605     DialogBox(hInstance, "DEVICE", hWnd, (DLGPROC)devicedialogproc);
00606 
00607         Console.Open();
00608 
00609     if(DialogBox(hInstance, "STARTDLG", hWnd, (DLGPROC)StartProc) == IDOK)
00610     {
00611         if (!InitGL(screen.right, screen.bottom))
00612         {
00613             SendMessage(hWnd, WM_CLOSE, 0, 0);
00614         }
00615         else
00616         {
00617             ShowWindow(hWnd, SW_SHOW);
00618             UpdateWindow(hWnd);
00619             SetFocus(hWnd);
00620             wglMakeCurrent(hDC,hRC);
00621             SetCursorPos((int)(screen.right * 0.5), (int)(screen.bottom * 0.5));
00622             ShowCursor(0);
00623         }
00624     }
00625     else
00626     {
00627         delete[] brushPolygons;
00628         delete[] Brush;
00629         delete[] vertex1;
00630         delete[] vertex2;
00631         delete[] vertex3;
00632         delete[] lightmap;
00633         delete[] staticlight;
00634         delete[] texture;
00635         delete[] vertex;
00636         delete[] camera;
00637         delete[] light;
00638         delete[] worldPolygons;
00639         delete[] bspPolygons;
00640         delete root;
00641         delete[] bullet;
00642         PostQuitMessage(0);
00643     }
00644 
00645     while (1)
00646     {
00647         while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
00648         {
00649             if (GetMessage(&msg, NULL, 0, 0))
00650             {
00651                 TranslateMessage(&msg);
00652                 DispatchMessage(&msg);
00653             }
00654             else
00655             {
00656                 return TRUE;
00657             }
00658         }
00659 
00660         if(!DialogInUse)
00661         {
00662             SetCursorPos((int)(screen.right * 0.5), (int)(screen.bottom * 0.5));
00663             DrawGLScene();
00664             glFlush();
00665             SwapBuffers(hDC);
00666         }
00667 
00668         multiplier = GetTimePassed(lasttime, average, lastmultiplier);
00669         camera[currentCamera].Multiplier = multiplier;
00670         light[currentLight].Multiplier = multiplier;
00671         for (int loop = 0; loop < numBullets; loop++)
00672             bullet[loop].Multiplier = multiplier;
00673 
00674         if (key['A'] && released_key['A'] == 0 && CSGflag == 1)
00675         {
00676             CSGAddition();
00677             released_key['A'] = 1;
00678         }
00679 
00680         if (!key['A'])
00681             released_key['A'] = 0;
00682 
00683         if (key['T'] && released_key['T'] == 0)
00684         {
00685             Texturing = !Texturing;
00686             released_key['T'] = 1;
00687         }
00688 
00689         if (!key['T'])
00690             released_key['T'] = 0;
00691 
00692         if (key['C'] && released_key['C'] == 0)
00693         {
00694             CSGcullface = !CSGcullface;
00695             released_key['C'] = 1;
00696         }
00697 
00698         if (!key['C'])
00699             released_key['C'] = 0;
00700 
00701         if (key['R'] && released_key['R'] == 0)
00702         {
00703             ResetBrushes();
00704             released_key['R'] = 1;
00705         }
00706 
00707         if (!key['R'])
00708             released_key['R'] = 0;
00709 
00710         if (key['M'] && released_key['M'] == 0)
00711         {
00712             if (cameraMode == 2)
00713                 cameraMode = 0;
00714             else
00715                 cameraMode = 2;
00716             released_key['M'] = 1;
00717         }
00718 
00719         if (!key['M'])
00720             released_key['M'] = 0;
00721 
00722         if (key['F'])
00723         {
00724             // Loop through all bullets
00725             for (int loop = 0; loop < numBullets; loop++)
00726             {
00727                 // Get current time
00728                 float shotthis = (float)GetTickCount();
00729                 // If last time in NULL then this is the first time fired
00730                 if (shotlast == 0)
00731                     shotlast = ApplicationStartTime;
00732                 // Get the interval between shots
00733                 float shotoffset = shotthis - shotlast;
00734                 // If minimum interval has passed and bullet is inactive
00735                 if (shotoffset > 100 && bullet[loop].active != true)
00736                 {
00737                     // This time becomes last time fired
00738                     shotlast = shotthis;
00739                     // Set a flag to indicate that this is the first time fired
00740                     bullet[loop].flag = true;
00741                     // Set the bullet to active
00742                     bullet[loop].active = true;
00743                     // Set the bullets direction vector
00744                     bullet[loop].VelocityVector = camera[currentCamera].GetZUnit();
00745                     // Set the bullets orientation
00746                     bullet[loop].Orientation = camera[currentCamera].Orientation;
00747                     // Set the bullets position
00748                     bullet[loop].OriginalPosition = camera[currentCamera].Position;
00749                     bullet[loop].PreviousPosition = camera[currentCamera].Position;
00750                     bullet[loop].Position = camera[currentCamera].Position;
00751                     // Increase the number of bullets active counter
00752                     numBulletsActive++;
00753                     // Make the muzzle-flash decal active
00754                     muzzleflashdecal.active = true;
00755                     // Play the gunshot sound
00756                     PlayChannel(channel_gunshot);
00757 
00758                     break;
00759                 }
00760             }
00761         }
00762 
00763         if (key['1'])
00764         {
00765             step = 10.0;
00766         }
00767 
00768         if (key['2'])
00769         {
00770             step = 20.0;
00771         }
00772 
00773         if (key['3'])
00774         {
00775             step = 30.0;
00776         }
00777 
00778         if (key['4'])
00779         {
00780             step = 40.0;
00781         }
00782 
00783         if (key['5'])
00784         {
00785             step = 50.0;
00786         }
00787 
00788         if (key['6'])
00789         {
00790             step = 60.0;
00791         }
00792 
00793         if (key['7'])
00794         {
00795             step = 70.0;
00796         }
00797 
00798         if (key['8'])
00799         {
00800             step = 80.0;
00801         }
00802 
00803         if (key['9'])
00804         {
00805             step = 90.0;
00806         }
00807 
00808         if (key['0'])
00809         {
00810             step = 100.0;
00811         }
00812 
00813         if (key[VK_NUMPAD6])
00814         {
00815             light[currentLight].Movement_x += step;
00816         }
00817 
00818         if (key[VK_NUMPAD4])
00819         {
00820             light[currentLight].Movement_x -= step;
00821         }
00822 
00823         if (key[VK_NUMPAD2])
00824         {
00825             light[currentLight].Movement_z += step;
00826         }
00827 
00828         if (key[VK_NUMPAD8])
00829         {
00830             light[currentLight].Movement_z -= step;
00831         }
00832 
00833         if (key[VK_NUMPAD7])
00834         {
00835             light[currentLight].Movement_y += step;
00836         }
00837 
00838         if (key[VK_NUMPAD9])
00839         {
00840             light[currentLight].Movement_y -= step;
00841         }
00842 
00843         if (key[VK_NUMPAD5] && released_key[VK_NUMPAD5] == 0)
00844         {
00845             if (light[currentLight].Positional == FALSE)
00846                 light[currentLight].Positional = TRUE;
00847             else
00848                 light[currentLight].Positional = FALSE;
00849             released_key[VK_NUMPAD5] = 1;
00850         }
00851 
00852         if (!key[VK_NUMPAD5])
00853             released_key[VK_NUMPAD5] = 0;
00854 
00855         if (key[VK_RIGHT])
00856         {
00857             camera[currentCamera].Movement_x += step;
00858         }
00859 
00860         if (key[VK_LEFT])
00861         {
00862             camera[currentCamera].Movement_x -= step;
00863         }
00864 
00865         if (key[VK_DOWN])
00866         {
00867             camera[currentCamera].Movement_z += step;
00868         }
00869 
00870         if (key[VK_UP])
00871         {
00872             camera[currentCamera].Movement_z -= step;
00873         }
00874 
00875         if (key[VK_PRIOR])
00876         {
00877             camera[currentCamera].Movement_y += step;
00878         }
00879 
00880         if (key[VK_NEXT])
00881         {
00882             camera[currentCamera].Movement_y -= step;
00883         }
00884 
00885         if (key[VK_SPACE])
00886         {
00887             camera[currentCamera].Reset();
00888         }
00889 
00890         if (key[VK_ESCAPE] || key['Q'])
00891             SendMessage(hWnd,WM_CLOSE,0,0);
00892     }
00893 }

LRESULT CALLBACK WndProc HWND    hWnd,
UINT    message,
WPARAM    wParam,
LPARAM    lParam
 

Definition at line 360 of file main.cpp.

References cameraMode, Console, currentCamera, DeleteBullets(), DeleteSpline(), DrawGLScene(), FALSE, LinkedList< T >::Get(), glFontDestroy(), hDC, hRC, hWnd, key, numportals, numSplines, ps, ReSizeGLScene(), screen, TRUE, and PORTAL::Vertex.

Referenced by WinMain().

00364 {
00365     GLuint    PixelFormat;
00366     int generic_format;
00367     int generic_accelerated;
00368     PIXELFORMATDESCRIPTOR pfd_new;
00369   
00370     static PIXELFORMATDESCRIPTOR pfd=
00371     {
00372            sizeof(PIXELFORMATDESCRIPTOR),
00373         1,
00374         PFD_DRAW_TO_WINDOW |
00375         PFD_SUPPORT_OPENGL |
00376         PFD_DOUBLEBUFFER,
00377         PFD_TYPE_RGBA,
00378         16,
00379         0, 0, 0, 0, 0, 0,
00380         0,
00381         0,
00382         0,
00383         0, 0, 0, 0,
00384         16,
00385         0,
00386         0,
00387         PFD_MAIN_PLANE,
00388         0,
00389         0, 0, 0
00390     };
00391 
00392 
00393     switch (message)
00394     {
00395         case WM_CREATE:
00396             hDC = GetDC(hWnd);
00397 
00398             PixelFormat = ChoosePixelFormat(hDC, &pfd);
00399 
00400              if (!PixelFormat)
00401             {
00402                    MessageBox(NULL,"Can't find a suitable PixelFormat.","Error",MB_OK|MB_ICONERROR);
00403                 PostQuitMessage(0);
00404                 break;
00405             }
00406 
00407             if(!SetPixelFormat(hDC,PixelFormat,&pfd))
00408             {
00409                 MessageBox(NULL,"Can't set the PixelFormat.","Error",MB_OK|MB_ICONERROR);
00410                 PostQuitMessage(0);
00411                 break;
00412             }
00413 
00414             hRC = wglCreateContext(hDC);
00415             if(!hRC)
00416             {
00417                 MessageBox(NULL,"Can't create a GL Rendering Context.","Error",MB_OK|MB_ICONERROR);
00418                 PostQuitMessage(0);
00419                 break;
00420             }
00421 
00422             if(!wglMakeCurrent(hDC, hRC))
00423             {
00424                 MessageBox(NULL,"Can't activate the GL Rendering Context.","Error",MB_OK|MB_ICONERROR);
00425                 PostQuitMessage(0);
00426                 break;
00427             }
00428             break;
00429 
00430         case WM_SYSCOMMAND:
00431         {
00432             switch (wParam)
00433             {
00434                 case SC_SCREENSAVE:
00435                 case SC_MONITORPOWER:
00436                     return 0;
00437             }
00438             break;
00439         }
00440 
00441         if (DialogInUse)
00442         {
00443             case WM_PAINT:
00444                 BeginPaint(hWnd,&ps);
00445                 DrawGLScene();
00446                 glFlush();
00447                 SwapBuffers(hDC);
00448                 EndPaint(hWnd,&ps);
00449             break;
00450         }
00451 
00452         case WM_CLOSE:
00453             delete[] lightmap;
00454             delete[] staticlight;
00455             delete[] texture;
00456             delete[] vertex;
00457             delete[] camera;
00458             delete[] light;
00459             delete[] worldPolygons;
00460 
00461             for (int i = numSplines - 1; i >= 0; i--)
00462                 DeleteSpline(i, SplineList);
00463 
00464 // TODO: Fix This
00465 //            if (BuiltBSP)
00466 //                DeleteBSP(root);
00467 //            delete root;
00468 
00469             for (int i = numportals; i > 0; i--)
00470             {
00471                 portal = PortalList.Get(i);
00472                 delete[] portal->Vertex;
00473             }
00474            
00475             glFontDestroy(&myFont);
00476             
00477             BASS_Stop();             // Stop all samples playing
00478             BASS_Free();             // Free the BASS resources
00479 
00480             DeleteBullets();
00481             
00482             CLog::addLine("--- End of Program ---");
00483             Console.Close();
00484 
00485             ChangeDisplaySettings(NULL, 0);
00486             wglMakeCurrent(hDC,NULL);
00487             wglDeleteContext(hRC);
00488             ReleaseDC(hWnd,hDC);
00489             DestroyWindow(hWnd);
00490         break;
00491 
00492         case WM_DESTROY:
00493             PostQuitMessage(0);
00494         break;
00495 
00496         case WM_KEYDOWN:
00497             key[wParam] = TRUE;
00498         break;
00499 
00500         case WM_KEYUP:
00501             key[wParam] = FALSE;
00502         break;
00503 
00504         case WM_SIZE:
00505             SetCursorPos((int)(screen.right * 0.5), (int)(screen.bottom * 0.5));
00506             ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));
00507         break;
00508 
00509         case WM_MOUSEMOVE:
00510             if (cameraMode == 0)
00511             {
00512                 camera[currentCamera].Delta_x = float(HIWORD(lParam) - screen.bottom * 0.5) * 10;
00513                 camera[currentCamera].Delta_y = float(LOWORD(lParam) - screen.right * 0.5) * 10;
00514             }
00515         break;
00516 
00517         case WM_LBUTTONDOWN:
00518             camera[currentCamera].Delta_z = -120.0;
00519         break;
00520 
00521         case WM_RBUTTONDOWN:
00522             camera[currentCamera].Delta_z = 120.0;
00523         break;
00524 
00525         case WM_LBUTTONUP:
00526             if (wParam != MK_RBUTTON)
00527                 camera[currentCamera].Delta_z = 0.0;
00528         break;
00529 
00530         case WM_RBUTTONUP:
00531             if (wParam != MK_LBUTTON)
00532                 camera[currentCamera].Delta_z = 0.0;
00533         break;
00534 
00535         default:
00536             return (DefWindowProc(hWnd, message, wParam, lParam));
00537     }
00538     return (0);
00539 }


Variable Documentation

char AppDirectory[MAX_PATH]
 

Definition at line 53 of file main.cpp.

Referenced by StartProc(), and WinMain().

float ApplicationStartTime
 

Definition at line 54 of file main.cpp.

Referenced by bsplinepoint(), InitGL(), and WinMain().

const int average = 10
 

Definition at line 73 of file main.cpp.

Referenced by GetTimePassed(), and WinMain().

BRUSH* Brush = new BRUSH[3]
 

Definition at line 155 of file main.cpp.

POLYGON* brushPolygons = new POLYGON[14]
 

Definition at line 153 of file main.cpp.

LinkedList<PORTAL> BrushPortalList
 

Definition at line 163 of file main.cpp.

BRUSH* BrushSet = NULL
 

Definition at line 154 of file main.cpp.

POLYGON* bspPolygons = new POLYGON[numWorldPolygons]
 

Definition at line 92 of file main.cpp.

bool BuiltBSP = false
 

Definition at line 148 of file main.cpp.

Referenced by InitGL().

BULLET* bullet = new BULLET[numBullets]
 

Definition at line 142 of file main.cpp.

int bulletspeed = 0
 

Definition at line 137 of file main.cpp.

int bullettype = 1
 

Definition at line 138 of file main.cpp.

CAMERA* camera = new CAMERA[numCameras + 1]
 

Definition at line 98 of file main.cpp.

int cameraMode = 2
 

Definition at line 177 of file main.cpp.

Referenced by InitGL(), WinMain(), and WndProc().

LinkedList<SOUND_CHANNEL> ChannelList
 

Definition at line 134 of file main.cpp.

ConsoleWindow Console
 

Definition at line 44 of file main.cpp.

Referenced by WinMain(), and WndProc().

bool CSGcullface = 1
 

Definition at line 195 of file main.cpp.

Referenced by WinMain().

bool CSGflag = 0
 

Definition at line 194 of file main.cpp.

Referenced by CSGAddition(), and WinMain().

int currentCamera = 0
 

Definition at line 66 of file main.cpp.

Referenced by DrawGLScene(), UpdateListener(), WinMain(), and WndProc().

int currentleaf = 0
 

Definition at line 146 of file main.cpp.

Referenced by DrawGLScene().

int currentLight = 0
 

Definition at line 79 of file main.cpp.

Referenced by DrawHalo(), and WinMain().

int currentSpline = 0
 

Definition at line 178 of file main.cpp.

Referenced by LoadSplines().

int device
 

Definition at line 129 of file main.cpp.

Referenced by devicedialogproc(), and InitializeBASS().

int DialogInUse = 0
 

Definition at line 112 of file main.cpp.

Referenced by ColorDialogHook(), and WinMain().

float epsilon = 0.05
 

Definition at line 59 of file main.cpp.

int fps
 

Definition at line 75 of file main.cpp.

Referenced by DrawMyText(), and GetTimePassed().

PLANE frustum[6]
 

Definition at line 83 of file main.cpp.

HINSTANCE g_hInst
 

Definition at line 50 of file main.cpp.

Referenced by WinMain().

int GL_LIGHT[8] = {GL_LIGHT0, GL_LIGHT1, GL_LIGHT2, GL_LIGHT3, GL_LIGHT4, GL_LIGHT5, GL_LIGHT6, GL_LIGHT7}
 

Definition at line 78 of file main.cpp.

HDC hDC
 

Definition at line 48 of file main.cpp.

Referenced by WinMain(), and WndProc().

HGLRC hRC
 

Definition at line 47 of file main.cpp.

Referenced by WinMain(), and WndProc().

HWND hWnd
 

Definition at line 49 of file main.cpp.

Referenced by GetLightColor(), WinMain(), and WndProc().

HWND hWndStartDlg
 

Definition at line 111 of file main.cpp.

Referenced by StartProc().

DECAL impactflashdecal
 

Definition at line 104 of file main.cpp.

bool key[256]
 

Definition at line 62 of file main.cpp.

Referenced by WinMain(), and WndProc().

CAMERA LastCam
 

Definition at line 99 of file main.cpp.

float lastmultiplier[average]
 

Definition at line 74 of file main.cpp.

Referenced by GetTimePassed(), and WinMain().

float lasttime
 

Definition at line 71 of file main.cpp.

Referenced by GetTimePassed(), and WinMain().

LinkedList<BSP_node> LeafList
 

Definition at line 185 of file main.cpp.

LIGHT* light = new LIGHT[numLights + 1]
 

Definition at line 107 of file main.cpp.

float lightColor[3] = {1.0, 1.0, 1.0}
 

Definition at line 108 of file main.cpp.

Referenced by GetLightColor().

Lightmap* lightmap = new Lightmap[numWorldPolygons]
 

Definition at line 172 of file main.cpp.

Referenced by CreateLightmaps().

BSP_node* listnode
 

Definition at line 187 of file main.cpp.

int lookAtPath = 0
 

Definition at line 179 of file main.cpp.

Referenced by LoadSplines().

BOOL lowqual
 

Definition at line 130 of file main.cpp.

Referenced by devicedialogproc(), and InitializeBASS().

float Max_X
 

Definition at line 119 of file main.cpp.

Referenced by CreateLargePortal(), and InitGL().

float Max_Y
 

Definition at line 119 of file main.cpp.

Referenced by CreateLargePortal(), and InitGL().

float Max_Z
 

Definition at line 119 of file main.cpp.

Referenced by CreateLargePortal(), and InitGL().

int maxDecals = 100
 

Definition at line 102 of file main.cpp.

float Min_X
 

Definition at line 119 of file main.cpp.

Referenced by CreateLargePortal(), and InitGL().

float Min_Y
 

Definition at line 119 of file main.cpp.

Referenced by CreateLargePortal(), and InitGL().

float Min_Z
 

Definition at line 119 of file main.cpp.

Referenced by CreateLargePortal(), and InitGL().

float multiplier
 

Definition at line 72 of file main.cpp.

Referenced by GetTimePassed(), and WinMain().

DECAL muzzleflashdecal
 

Definition at line 103 of file main.cpp.

GLFONT myFont
 

Definition at line 116 of file main.cpp.

int numBrushes = 3
 

Definition at line 152 of file main.cpp.

int numBullets = 50
 

Definition at line 140 of file main.cpp.

Referenced by WinMain().

int numBulletsActive = 0
 

Definition at line 139 of file main.cpp.

Referenced by WinMain().

int numCameras = 4
 

Definition at line 67 of file main.cpp.

Referenced by SetGLCamera().

int numChannels = 0
 

Definition at line 132 of file main.cpp.

Referenced by CreateChannel().

int numcurrentportals = 0
 

Definition at line 126 of file main.cpp.

int numleaves = 0
 

Definition at line 145 of file main.cpp.

Referenced by CountVisibleLeaves().

int numleavesvisible = 0
 

Definition at line 122 of file main.cpp.

Referenced by DrawGLScene().

int numLightmaps = 0
 

Definition at line 171 of file main.cpp.

Referenced by CreateLightmaps().

int numLights = 0
 

Definition at line 80 of file main.cpp.

Referenced by DrawGLScene(), and SetGLLighting().

int numlistleaves = 0
 

Definition at line 124 of file main.cpp.

Referenced by MakeNodeLists().

int numlistpartitions = 0
 

Definition at line 125 of file main.cpp.

Referenced by MakeNodeLists().

int numpartitions = 0
 

Definition at line 147 of file main.cpp.

Referenced by MakePortalList().

int numportals = 0
 

Definition at line 161 of file main.cpp.

Referenced by WndProc().

int numSamples = 0
 

Definition at line 131 of file main.cpp.

Referenced by LoadSample().

int numSplines = 0
 

Definition at line 176 of file main.cpp.

Referenced by LoadSplines(), SetSplines(), and WndProc().

int numStaticLights = 9
 

Definition at line 167 of file main.cpp.

Referenced by CreateLightmaps().

int numVertices = 37
 

Definition at line 86 of file main.cpp.

int numWorldPolygons = 58
 

Definition at line 90 of file main.cpp.

Referenced by DrawGLScene(), InitGL(), and SetGLWorld().

LinkedList<BSP_node> PartitionList
 

Definition at line 186 of file main.cpp.

float pi = 3.141592
 

Definition at line 57 of file main.cpp.

Referenced by OBJECT::GetXUnit(), OBJECT::GetYUnit(), OBJECT::MoveX(), and OBJECT::MoveY().

ParticleManager PManager
 

Definition at line 190 of file main.cpp.

PORTAL* portal
 

Definition at line 164 of file main.cpp.

LinkedList<PORTAL> PortalList
 

Definition at line 162 of file main.cpp.

PAINTSTRUCT ps
 

Definition at line 52 of file main.cpp.

Referenced by WndProc().

float radian = pi / 180
 

Definition at line 58 of file main.cpp.

Referenced by OBJECT::Rotate().

bool released_key[256]
 

Definition at line 63 of file main.cpp.

Referenced by WinMain().

BSP_node* root = new BSP_node
 

Definition at line 149 of file main.cpp.

LinkedList<SOUND_SAMPLE> SampleList
 

Definition at line 133 of file main.cpp.

RECT screen
 

Definition at line 51 of file main.cpp.

Referenced by WinMain(), and WndProc().

float shotlast
 

Definition at line 141 of file main.cpp.

Referenced by WinMain().

int showportals = 0
 

Definition at line 123 of file main.cpp.

SPLINE* spline
 

Definition at line 181 of file main.cpp.

char SplineFileName[MAX_PATH]
 

Definition at line 180 of file main.cpp.

Referenced by StartProc().

LinkedList<SPLINE> SplineList
 

Definition at line 182 of file main.cpp.

StaticLight* staticlight = new StaticLight[numStaticLights]
 

Definition at line 168 of file main.cpp.

float step = 30.0
 

Definition at line 68 of file main.cpp.

Referenced by WinMain().

char szText[BUFFER_SIZE]
 

Definition at line 113 of file main.cpp.

Referenced by StartProc().

TEXTURE* texture = new TEXTURE[11]
 

Definition at line 95 of file main.cpp.

bool Texturing = 0
 

Definition at line 193 of file main.cpp.

Referenced by WinMain().

VERTEX* vertex = new VERTEX[numVertices]
 

Definition at line 87 of file main.cpp.

VERTEX* vertex1 = new VERTEX[8]
 

Definition at line 156 of file main.cpp.

VERTEX* vertex2 = new VERTEX[8]
 

Definition at line 157 of file main.cpp.

VERTEX* vertex3 = new VERTEX[8]
 

Definition at line 158 of file main.cpp.

int visible = 0
 

Definition at line 175 of file main.cpp.

POLYGON* worldPolygons = new POLYGON[numWorldPolygons]
 

Definition at line 91 of file main.cpp.


Generated on Fri Dec 23 05:15:50 2005 for Constructive Solid Geometry by doxygen1.2.15