Ray-tracing the Cornell Box results in really inconsistent image
Two symptoms

There appear to be two problems with the image.


The background is showing through along the line between adjacent triangles.
The colour displayed is not always from the closest intersection.


Note that the background colour is white, rather than black, due to the line:

                PutPixelSDL(screen, x, y, vec3(1, 1, 1));


Why this background shows through at the triangle edges I do not know. However, the second problem is identified below, so I recommend you fix that first and then the first problem can be analysed in isolation without the additional distractions.



Cause of the problem with ClosestIntersection

The ClosestIntesection function returns true when an intersection is found, and updates an Intersection object called closestIntersection. However, the intersection stored here is not always the closest to the camera.

The reason for this is here:

                closestIntersection.distance = glm::distance(start, x);


This appears in two places so it will need to be fixed in both.

start is cameraPos, presumably in world coordinates. x appears to be in the local coordinates of the triangle being intersected (one of the triangle vertices being the origin). The distance between two points in different coordinate systems is meaningless, so that in different regions of a triangle it will appear to be behind or in front of another triangle for no immediately apparent reason.

If x is first converted to world coordinates then the distance will be correct and the intersection chosen will be the closest to the camera.