3D Engine Design - 2nd Stage Prototype

From the original Xaede archive. This is historical writing, preserved in a new reading edition. Technical advice, tools and project status reflect the time of publication.

The second stage prototype essentially comprised of an effort to take the lessons-learned from the first stage of development, and create a prototype game engine using the C++ programming language. This language was chosen in order to present a cohesive, object-oriented API to a potential future user of the game engine. This would allow them to implement their game engine, including such things as graphics, gameplay management, and artificial intelligence using a standard OO paradigm. However, what resulted from the stage two development was a nice framework for developing various game engine components, but lacking cohesive design elements that made the various independent elements a solid platform.

Since the use of GLUT was found to be severely limiting to the implementation of a gaming engine, it was decided that the Simple Direct-media Layer or SDL will be used in order to interface with windowing systems, and that the use of OpenGL will be retained, in order for the lessons learned in the stage one development process to be used in the second stage.

The second stage began with the implementation of classes to handle the management of frame rate, setting up the engine’s rendering environment, and managing the rendering process. This was quickly expanded, using code from the first stage as a model, to create classes for color management and dynamic polygon model management. These initial pieces were then used to render some of the simple polygon objects used in stage one. Additional components such as a lighting class and a timing class were added based upon the stage one components.

In order to be able to perform simple keyboard input, the SDL API was used to trap key events such as the escape key in order to make simple manipulations of the game engine environment while it was running.

The next step consisted of determine how texture mapping worked, both using OpenGL and the SDL API for loading and rendering bitmaps as they applied to object models. The texture class was created to load and process a bitmap file into a GL texture map.

In order to proceed to more complex polygon models, a new class was created to define what comprises a model within the Xaede game engine. Then, two model-importing classes were created that can natively read either 3DS or Milkshape model formats, and convert these to the Xaede model format for rendering and manipulation by the game engine.

Since the more complex models clearly illustrated a need for reading, initializing, and rendering textures, the texture class was enhanced to fulfill this need. Once the texture was registered with OpenGL, it could be reloaded & reinitialized from memory as needed, so the texture class acted as a crude caching mechanism for textures as well.

In order to determine when two models collided with each other, a simple class to calculate collisions using a new three-dimensional vector math class was implemented to handle this. This also served as an excellent framework for experimenting with collision modeling and the various optimizations used to enhance collision-detection performance.

When two models collided, it was determined that it would be nice to see some sort of effect – like an explosion – to be shown when this event occurred. Several different particle engines where then written, before consolidating on a particle engine type from which generic effects could be derived, e.g. explosions, fire, etc.
At this point, further consideration was given to user input, including both mouse and keyboard input. The result of this was to create a keyboard class to manage the keyboard input state, as well as a mouse class to handle mouse input events. These were designed to be used by the game engine or it sub-components to obtain user input. However, lessons learned during implantation suggest that there were better ways to create both the API as well as some of the internal components to the user-input management classes.

Once a working methodology for obtaining user input was completed, it was noted that there was no simple way to display text that would work well on multiple platforms. Upon research into this issue, it was determined to use the TTF (true type fonts) extension to the SDL library to render text as a TTF on top of OpenGL. This turned out to not be quite as simple as first thought, but it was eventually discovered that the OpenGL initialization needed to happen in such a fashion so that SDL surfaces could be blitted on top of the OpenGL screen. The font class was then created to handle this requirement. From the font class, the text class was derived to control the text displayed to the screen.

Given the current complex models, it was decided that the skeleton model manipulation system should be reimplemented in the stage two prototype using the lessons learned from the first stage to provide a consistent API for manipulation three-dimensional polygon objects.

Project Statistics

Language: C++ (lines of code: 5,585)
External libraries used: OpenGL, SDL
Modules created:

  • Base (framerate, GL lights, rendering pipeline, setup, timing)
  • Format (3DS, milkshape)
  • Graphics (colors, polygons, skeletal system, textures)
  • Input (keyboard, mouse)
  • Physics (vector 3D math)