Details of Assignment:
- The main part of the assignment was to make the graphics class completely platform independent
- The Second task was to create 3D objects using an Index buffer and a vertex buffer, Vertex Buffer is a list of all vertices in a shape whereas the Index buffer is the order/winding of all vertices needed to create the shape (for Reference, to create a Square with 2 Triangles, vertex buffer would be 4 corners of the square, and index buffer would be 6, 3 vertices * 2 triangles, which will reference to vertex buffer to get the location of the vertex)
- Lastly, I need to create a second object with a new shader effect
Running Part of Assignment:
- The Image below shows running on all 4 configurations
Fig 1. Image of all configuration running
How I Reach till this Point:
- The biggest challenge of the assignment was to make Graphics.cpp platform independent
- To do that, first of all I found all the differences between the Open GL and Direct 3D graphics file
- By doing that, I found that the differences were present in views which is part of Direct 3D rendering
- To separate the view section, I created a new header file cViewData.h and platform dependent .cpp files for Direct 3D and OpenGL
- Along with view functions, I added the Clear Background and swap buffer into the cViewData.h and combined them because I think they are related to viewing.
- Than, I changed the back buffer color, by calling the function through viewData object
Fig 2. Screenshot for clearing back-buffer with Red Color
Fig 3. Screenshot of frame being clear with red color
- Then I changed my function related to graphics and shader effects to make them dynamic and not fixed to Graphics
- For shader effects, I gave 2 character arrays (string) variables as a parameters which are actually the location for both vertex and fragment shaders, because these location are the one that specifies what shaders effects are bind to a object so passing these locations make the function dynamic
Fig 4. Screenshot of my shader effect data being initialized
- The Size of shader effect object for Direct 3D is 12 Byte and for Open GL is 16 Byte
- For both Direct 3D and Open GL there are 3 common variables which holds the shader data (vertex shader, fragment shader and rendering state), each being 4 Byte, while Open GL has extra 4 bytes for program ID which hold data for your program and links your shaders to it. So, I think the size 12 for D3D and 16 for Open GL is as minimum it needs to work
- For Graphics the user needs to specify 4 values, vertex Count, vertex data, index count, index data.
Fig 5 screenshot of my geometry object being initialized
- My Geometry object takes 32 Byte for Direct3D and 16 Byte for OpenGL
- My Geometry class has 4 variables for both Direct 3D and Open GL, 1 common and 3 separates.
- The common variable is the length for index buffer which is 4 Byte.
- The need for index count is because we need to know how many objects are created which can be easily know by length of index buffer as that many vertices needs to be drawn on the screen.
- Open GL has 3, 4 Byte variable, each for storing ID for index buffer, vertex buffer and vertex array.
- On the other hand, Direct 3D have 2 pointers to the buffers (index and vertex buffers) which are 8 Bytes each and a 12 Bytes vertex format.
- Which are all required and hold important data for the shape.
- So, I think the Geometry class is also as small it can be for the program to work.
- The Optional challenge for this assignment was to make the back-buffer color animate to different color
- To do that I took simulation time and passed it to sin function resulting into multiple colors
- I have divided the simulation time with a constant number, the reason for that is each would generate a different value which results in different values for each (R, G, B), values there by creating a greater number of color than it can do for same value
Fig 6. Code for making the back-buffer animate
It took me around 8-9 hours to do this assignment