A downloadable project

This week we are working within our engine code and refactoring our graphics. To do this, we needed to look into the graphics pipeline to create a platform-independent interface for meshes and effects. For these new objects to be platform-independent, they needed to be able to be used in OpenGL and Direct3D with the same function calls. This will benefit us in the future with code reusability, since I will be able to use the same code across multiple platforms. Also, the uniform and consistent look of the code will help with maintenance.  

I started implementing these changes by creating a cMesh and cEffect class. The cMesh class will define (or draw) the boundaries, and cEffect will control the shader (color) over it. Something to keep in mind: triangles are drawn with vertices, and the direct matters for Direct3D and OpenGL. If they are drawn in the wrong direction, the face of the mesh will be facing the opposite direction and will show up as if it’s clear. Direct3D vertices need to move in a clockwise direction, and OpenGL’s moves counterclockwise. 

For the platform independence of cMesh and cEffect’s methods, Graphics.d3d.cpp and Graphics.gl.cpp use the same calls to initialize, draw, bind, and clean. See Bellow:

In the remaining code, one of the main differences between Graphics.d3d.cpp and Graphics.gl.cpp is the initialization of views. Direct3D initializes a view to render a target on the screen, while OpenGL doesn’t do this step. We could add this step to cEffect initialize so that they happen simultaneously when an effect is initialized for Direct3D. This would allow us to use a single platform-independent Graphics.cpp.

After the new classes were created and implemented, I added some more hard-coded vertices to make a new triangle, and thus, a square was born. The next step was centering it and adding a roof for a house. 

For the Direct3D vertices, I tried something a bit harder and made a cat. It was interesting to think about how a shape could be segmented into separate triangles. I used a graphing paper website to experiment and visualize my vertices. 

I ended up tweaking the cat to make it look less like a cupcake. 

A big issue I encountered during this assignment were the pointers I was using as class variables. This was fixed by forward-declaring the structures and classes that I was going to use. Apparently a forward declaration can be used to declare an object before its definition is compiled. This allows you to make a pointer to something that will be instantiated in the future and helps break circular dependencies

Download

Download
Chai_Assignment2.zip 421 kB

Leave a comment

Log in with itch.io to leave a comment.