Game Engineering – Building Game Engine – Part 1

The point of the first assignment was to integrate the ‘Graphics’ project given as a separate one into the main engine and add necessary dependencies to the ‘Graphics’ project and other projects in the engine solution so that there are no errors while building the engine from scratch. The given graphics project consisted of files specific to both DirectX and OpenGL with some common files containing wrapper classes for implementations in both frameworks. This is required for the engine to be cross platform compliant while using latest technologies that are specific to particular operating systems. Even though most of the functionality is the same in both frameworks, the way it is achieved is different with different API names and variable declarations.

After integrating the project, we created a sample game modelled to an example game given as part of engine. The example game displays a white triangle and we are required to change the name of the window and logo as part of the assignment. The name of the window was straightforward with changing a string. The logo on the other hand had to be an ‘.ico’ (icon) file, which then I had to link to the project first as an icon in the resource file and link it to the image and then define it as a value in the resource header file after which I could use it in the game.

The second requirement was to change the color of the triangle displayed by the game to any color other than white. I wrote a fragment shader1 that changes the color of a triangle being drawn on the screen. I used a time variable exposed as part of the shader to achieve the desired results which can be seen below.

The shader constantly changes color based on the absolute value sine and cosine of time. Since the shader uses values for Red, Green and Blue that should be between 0 and 1, this gives the desired output. The output should be the same when run on DirectX and OpenGL and since the functions I used to get this effect are the same in both, I did not have to change anything.

Some projects in the engine are also dependent on the graphics library and vice versa. All the projects in the engine are dependent on the application project which serves as the base class for all the other projects to inherit from. So adding the graphics project as a reference to this project made sure that it is included in every other project in the engine which is dependent on the graphics library. There was a issue with the application project where it was referencing a previous version of the graphics library and did not add graphics to the project dependencies even when added as a reference. This lead to most of us having an error with the game not building because it was unable to find the required libraries. It took some time to figure out the issue. I also had an issue where my game was building for every configuration except for Debug x86 which was also solved by this.

There were also a few optional challenges for us to complete.

  1. The first one was to find a way to re-declarations of constant buffers in each shader and declare them in one place. To accomplish this, I have added the declarations for these constant buffers in the “shaders.inc” include file, which is included in all the shaders and is called before the shader is built.
  2. The second is to either pause or slow down the rate of simulation of the game when the user presses a key. The engine already has functionality to take in user input from keyboard and also to change the simulation time and we just had to tie them both in one place. In my game, the simulation runs at half the speed when pressing the “Shift” key. This is done by setting the simulation time in the game to 0.5 and when user releases the key it is set back to 1.0.

Finally, I personally want to learn more about graphics and other low-level engine programming as part of the class. From the first assignment, even though it is not directly working with low level graphics APIs, I like that we would be rendering objects on the screen using abstracted function calls but I hope the class would lay more emphasis on graphics programming.

User Inputs

  1. Shift: Plays the game in slow motion when held
  2. Esc: Exits the game.

 

OpenGL(x86) Direct3D(x64)

Leave a Reply

Your email address will not be published. Required fields are marked *