FPS: First Person Shooter in OpenGL

by

Neal Patel

Abstract. As video games and the genre of first person shooter games and become increasingly popular, the detail in realism has made these such games a favorite to many gamers. First person shooter games originated back when games were 8-bit such as Atari 400’s Star Raiders, and have since evolved to the recent blockbuster Halo 2 for the Xbox, which sold over 150,000,000 units the first week the game was released. Countless games have come and go, due to the control problems that make maneuvering through worlds difficult. In this report we try to address these issues based on the technologies given to us with OpenGL (open graphics library), and SDL (simple direct media layer).

1. Introduction

The goal of this project is to create a basic first person shooter. From scratch, we created the game engine using OpenGL and SDK. The game features concepts such as model loading, collision detection, and texture mapping. The goal is to kill all the zombies before they kill you. Existing systems failed to make controls of the player through corridors and mazes difficult, which were not fluid in movement. With our system we were able to use strafing capabilities, through SDL, which solved these problems, making movement seem realistic. This is because movement is not only in four directions, but rather diagonal and as well.

2. Technological Background

2.1 OpenGL

OpenGL (Open Graphics Library) is the interface between graphics program and graphics hardware. It provides low-level functionality, where all objects are built from points, lines and convex polygons. Higher level objects like cubes are implemented as six four sided polygons. OpenGL is also system independent, where it does not assume anything about hardware or operating systems. It’s only concerned with efficiently rendering mathematically described scenes. With OpenGL there are no windowing capabilities. It is a however a state machine, where at any moment during the execution of a program there is a current model transformation, a current color, a current light type and position. Lastly, OpenGL is a rendering pipeline in which it defines objects mathematically, arranges objects in space relative to a viewpoint, calculates the color of the objects, and rasterizes the objects. All the commands used in OpenGL begin with letters gl. For instance, the following functions are all commonly used in OpenGL programs: glBegin, glEnd, glOrtho and glViewport. It supports features like 3-dimensions, lighting, anti-aliasing, shadows, textures, depth effects, etc.

2.2 SDL

Simple DirectMedia Layer is a cross-platform game programming library. SDL uses the OS's native multimedia support to provide fast graphics and low level access to sound, and input processing on several platforms. Such input devices are keyboard, mouse, and joystick. SDL also provides a portable way to create OpenGL contexts, and can be used as a much more powerful replacement for the GLUT toolkit. SDL currently supports Win32, Linux, FreeBSD, IRIX, MacOS, and BeOS. SDL is written in C, but works with C++ natively and has bindings to several other languages, including Java, Perl, PHP, and Python.

2.3 C/C++

A programming language derived from C, based on Object Oriented Programming (OOP) using classes. The programming model for OOP focuses on the data being used instead of procedures, which separates C++ from its predecessors. It is important to mention a lot of the source code provided for the software is written in C. This is due to the fact that OpenGL and SDL were primarily written for C. Therefore must of the tutorials and documentation we used to help guide us through implementation were in C. C and C++ are intertwined with each other such it was natural to use both languages in are code.

2.4 Milkshape 3D

The enemy for the game is a zombie that is created in Milkshape 3D. This program allows users to model and animate their objects and load them into their game world. Through this technology users can edit or create their own models and objects and load them directly into the program through a Milkshape loader file.

3. System Architecture

The following diagram is the OpenGL API (application program interface) under Windows systems. This is the basic concept presented for this system.

GLU is the OpenGL utility kit that provides the high level functions. Some features include 2D image scaling, Rendering 3D objects, automatic mipmap from a single image, and special-purpose transformations and matrices.

GDI is the Graphics Device Interface. The GDI architects designed it to make the graphics hardware entirely invisible to Windows programmers.

WGL or “wiggle functions” are what Microsoft Windows use for interaction or screen/window issues that need to be handled by the host operating system. Each operating system usually has a set of extensions that tie OpenGL together with the user interaction and window management of the host environment.

The following diagram below is the game architecture used in order to design the first person shooter game.

4. Design and Implementation Details

The first person shooter game presents several concepts that are provided by OpenGL in order for this system to run properly. C/C++ was the primarily language selected for the first person shooter due to the fact SDL and OpenGL allow to program games natively, since they are written in C.

The main concepts are particle effects, first person camera, model loading and displaying, texture loading and displaying, minimal yet efficient artificial intelligence, 3D collision detection, Billboarding, and random map generation. Also in this program, the enemy can be changed by simply created a new enemy using milkshape3d. It can be loaded into the program thanks to a milkshape load function. Included in this project are several class functions. They are Bullet, enemy, item, main, map, model, particle, particle effect, player, system, texture, and vector.

4.1 The algorithm for the enemy class is as follows:

Collision with walls: There are four points at the corners of a bounding square around the enemy, with sides of length Enemy*2. Movement along either the x or y axis is stopped whenever continuing would allow one of these points to enter a wall.

Collision with player: A collision is registered whenever the distance between the player and the monster is less than the sum of the enemy radius and the player radius.

Game play: Enemies die when they collide with the player, dealing damage to the player equal to 250/e where e is the initial number of enemies on the map. Eventually the game play will allow for enemy to be hit with a bullet.

4.2 The algorithm for the map class is as follows:

Concept provided: The map is generated randomly where the size of the rooms vary, as well as where they are played on the screen. Through this random map generation, when the smallest room will eventually develop into a hall with makes the maze seem realistic. Although this tends to leave a repeatable feel, while journeying through the world, the textures applied provide the game with a lasting appeal.

Algorithm: The map is generated first, by filling it with empty tiles, and border tiles are made solid. A random point is then selected, and either a horizontal or vertical line of walls is drawn across the room, leaving a door at the selected point. The process is called recursively until the rooms are of an acceptable size.

Enemy placement: a similar concept as the randomly generated map, however if the random point is in a wall or close to the player then another point is chosen. This continues until there are an adequate number of enemies to fill the map. The current default value for maximum number of enemies is set to 50 no matter how many rooms are randomly generated.

4.3 The algorithm for the player class is as follows:

Collision with walls: There are four points at the corners of a bounding square around the player, with sides of length player*2. Movement along either the x or y axis is stopped whenever continuing would allow one of these points to enter a wall.

4.4 The function of the system class:

This is deals with the system set up so the rest of the program will not have to. For instance initialization of SDL, OpenGL, and keyboard is done as well as shutdown the system and setup the viewport and projection matrix. This tends to make the system run smoother as all configurations are done in one file. It is should be noted that this is an assumption and has not been tested in a running environment. Please refer to Section 6 Conclusion and Future work on better ideas of trying to make the system run faster and easier.

4.5 The function of the texture class:

Concept provided: To load textures into the program allowing for a more realistic appeal. Texture mapping allows you to glue an image of a wall, ceiling, and floor (obtained, by creating bitmap files) to a polygon, and to draw the entire object as a single polygon. Texture mapping ensures that all the right things happen as the polygon is transformed and rendered: When the say the wall is viewed in perspective, for example, the bricks decrease in size along with the wall as the wall gets farther from the viewpoint. Other uses for texture mapping include vegetation to be textured on large polygons representing wallpaper patterns; and textures that make polygons appear to be made of natural substances such as marble, wood, or cloth. The possibilities are endless. Although it's most natural to think of applying textures to polygons, textures can be applied to all primitives - points, lines, polygons, bitmaps, and images.

Algorithm: Loads a BMP file via SDL’s LoadBMP routine. The texture is then formatted to be compatible with OpenGL’s texture routines and loaded into video memory.

Input/Output: loadTexture() takes a filename and returns a texture ID. Errors and status messages are sent to the console.

4.6 The User Interface

Controls / Actions
W or UP arrow / Move forwards
S or BACK arrow / Move backwards
A / Strafe Left
D / Strafe Right
Mouse Left or LEFT arrow / Look Left
Mouse Right or RIGHT arrow / Look Right
Mouse UP / Look Up
Mouse Down / Look Down
Enter / Fire (to be implemented)
Escape Key / Kill Application

5. System Requirements

5.1 System Requirements

In order maximize the full capabilities of this program a rather decent graphics card is required. The graphics cards must be OpenGL compliant. Some common graphics cards include ATI, and NVIDIA. Also the SDL library and OpenGL32 libraries need to be installed on the machine this game is running on. Please refer to Appendix A to see the user manual on how to install and run the software.

6. Screenshots

The above picture is a large room that can be found in the maze. Currently there are no enemies to kill in this room. Below is a screenshot of a typical live zombie that is found throughout the maze.

The above screenshot is one of the enemies who had his life terminated. This death was caused by a collision with the player.

6. Conclusion and Future Work

The controls are well implemented and the textures add to a scary yet creative scene. The enemies lack the AI that we anticipated but this allows us to add future implementation on this project. Also there are several functionalities in the program that need to be completed. One such functionality is being able to fire a weapon, which as of this moment does not occur. Other future plans on this game are the addition of the item pickup, which will allow the user to pick up several different types of guns, with the appropriate ammo type. Multiplayer and or online capabilities would also be a consideration for future plans of development. Although games take many years and people to fully design a masterpiece, the outcome of this game is satisfactory. Another creative aspect to the game we will likely consider is the addition of music and sound effects, which are supported by SDL. Great music and sound effects have always helped game play in videogames. Since they lack the much functionality that is typically required for a successful first person shooter it should not be considered in the genre of first person shooter. Though the first person view, fluidity of the camera, texture applied to the scene and overall lasting appeal are done quit well, the project has become a great learning experience.

7. References

Foley, James, A. van Dam, S.K. Feiner, J.F. Hughes. Computer Graphics - Principles and Practice. 2nd edition, Addison-Wesley, New York, 1990.

Hawkins, Kevin and Dave Astle. OpenGL Game Programming. Premier Press, May 2004.

Hill, F. S. Jr. Computer Graphics Using OpenGL. Prentice Hall, Upper Saddle River, New Jersey, 2001.

LaMothe, Andre. Tricks of the 3D Game Programming Gurus: Advanced 3D Graphics and Rasterization. Sams Publishing. June 2003.

Woo, Mason, J. Neider, and T. Davis. OpenGL Programming Guide. Addison-Wesley, fourth edition, November 2003.

Appendix A

User Manual

Download the library, header, and dll files into the appropriate directory in your compiler. The directory path is followed by the file name

- gl.h - C:\Program Files\Microsoft Visual Studio\VC98\include\GL

- glu.h - C:\Program Files\Microsoft Visual Studio\VC98\include\GL

- opengl32.lib - C:\Program Files\Microsoft Visual Studio\VC98\lib

- glu32.lib - C:\Program Files\Microsoft Visual Studio\VC98\lib

These files are all included in the FPS folder for download.

Once these files are downloaded to the appropriate directory open the folder labeled FPS. This is the workspace directory for the entire project. Double click on the main.exe file in the FPS folder and the application should run. It is important to note that the SDL libraries and DLL files are included in folder and must remain there. They are sdl.lib sdlmain.lib and sdl.dll. Also all the models and textures in which the program use for input are in the folder labeled Data. They must also remain inside the folder.