The goal of this Assignment_02 is to integrate Lua into the solution as well as adding the vertex buffer data to draw a square in the output instead of triangle which was done in the previous assignment.
The part of this Assignment which was fun to work on was creating another triangle and updating the Vertex Data for OpenGl and Direct3D. The important part was taking into account that the orientation in which you write the vertices are in clockwise direction for Direct3D and counter-clockwise direction for OpenGL. But since we discussed about these details in great depth in the class this task was easier . This was so interesting that I created different patterns and also made color changes in the fragment shaders just to whet my appetite in Graphics. I have shown examples in the end of this post.
First of all talking about the structure of the code we add Lua,LuaC and Lua.exe projects in the External folder. We also updated the previous AssetBuilder.cpp by writing functions to integrate it with Lua Scripting Language and add BuildAssets.lua file in the AssetBuilder project which does the actual building process.
Placing the BuildAsset.lua in the AssetBuilder project is a good idea because the AssetBuilder.cpp has communicate with the BuildAssets.lua to call functions from it . So I think that its is probably is good idea to just put the BuildAssets.lua in the AssetBuilder project for a smooth communication .
It is fascinating to know how BuildAssets.lua file can call upon C++ functions to deal with copying files which are modified and how the directories are created. Passing arguments and pushing it onto the stack and returning the values between the lua file and C++ is quite interesting.
The authored assets are basically contained in the assets folder.
. When the AssetBuilder project is build it checks whether those assets are present in the BuildAssets folder. If they are not, or they have been modified, it will basically copy those assets there.
When you build the AssetBuilder it calls the AssetBuilder.exe .The AssetBuilder.exe is used to call the lua script which is actually doing the building process. The lua file checks whether all the required authored assets exist in the Build Assets folder. If they are not, or have been modified or updated, it will copy those assets to the Build Assets folder.
Some of the strengths of lua is the ease of integration and the speed of execution. Lua integration was quite easy with C++ . However debugging Lua can be a problem . I had to check for syntax errors by running it on command prompt .
We are learning Lua in class because it is easy to integrate and learn. It is also used as the scripting language in many industries so it is probably beneficial to learn it . Probably the main advantage of lua and why it would be used in the game industry is that it allows us to make minor changes in the code without having to build the game everytime, thereby saving a lot of time especially when the game is really big . Another advantage that can thought of in our solution is that since the AssetBuilder has been modified to use the lua script file the asset building process can be tweaked from outside the C++ code to make quick changes to the asset building process.
The output of the Assigment_02 looks like the above picture . Instead of having a triangle in the last assignment, we add another triangle to form a square . The white color is passed in the fragment shader.
As per the graphics part it would be amazing to update the sVertex struct to add a z-axis which currently only contains x and y to draw 3D primitive shapes like cube and pyramids . Also if have a D3DCOLOR in the sVertex struct we can add separate color for different vertices and interpolate them across the face of the triangle to get some multicolored effects rather than having a single color in the fragment shader.
Just to whet my appetite for graphics I also created the following house looking structure by adding another triangle on top of the rectangle thereby having a total of 3 triangles . (2 triangles for the rectangle structure and one triangle on top of it).
I also experimented with the fragment shader and manipulated the RGBA color values to see how that would affect the output.
Overall it took me around 12 hours to finish this assignment. Going through the reading material and lua integration took most of the time which was around 10 hours and it took 2 hours for drawing the square which is one more triangle to the previous assignment and understanding the graphics for Direct3D and OpenGL.
You can download the Zip File of Assignment_02 from the following link to get the square output.
After downloading the link run Game.exe.