I made the following changes for this:
1) Added a projection matrix in the Renderer class and the following function for generating the matrix:
int SetPerspective(float aFov, float aAspectRatio, float aNear, float aFar);
This function creates a projection matrix, which later gets passed down to the VertexEngine class before drawing.
2) Added a function for setting the viewport in the Renderer class:
int SetViewPort(int aWidth, int aHeight, int aOffsetX, int aOffsetY);
This function passes down the viewport data to the VertexEngine class, which uses it to form a matrix that will later be used to transform from normalized device coordinates to screenspace.
3) In the VertexEngine class, I updated the 'ProcessVertex' function I had in there such that three extra steps are performed at the end:
- multiply world-view transformed vertex with the projection matrix to perform linear portion of perspective projection
- divide the result with Z coordinate (stored in the homogenous W coordinate) resulting in normalized device coordinates
- multiply the NDCs to screenspace by multiplying by the matrix created in step 2 above
After adding the appropriate calls to my test application, I get the following (there is a slight x-axis rotation going on so its from a front-top view) ...
The remaining tasks for the vertex stage are culling and frustum clipping.
Keep up the good work!