Pseudo-3D Rendering

This was a project I worked on because I wanted to try making some type of pseudo-3d using only 2d rendering in style with how older games had to simulate 3d graphics because of techical limitations. The project was made using c++ with nothing but the SDL library. With the SDL library I was able to use simple functions to render 2d squares (and sprites) to a simple window. I didn’t want to use anything more advanced since I wanted to try and recreate how older games used to implement this sort of functionality.

The basic road is made up of 2 parts: Firstly, there is what I call a “road-segment”. A road-segment is one horizontal line of the road. Secondly the layout of the road, such as curves and hills, are made up of multiple “map-segments”. A map-segment has 3 values which help calculate where each road-segment will be drawn, these 3 values are: Length(int), Curvature(float) and Hill(float). The Length value determines for how many road-segment one map-segment will last. The Curvature value determines how much the road should curve, a positive number curves the road to the right and a negative number to the left. Lastly, the Hill value does pretty much the same thing as the Curvature value, but curves the road vertically instead of horizontally. A positive Hill number will curve the road upwards, while a negative number will curve the road downwards.

Everything that is being drawn, is drawn back to front, meaning that the objects / textures that are the furthest away are drawn before the ones close to the camera. This is known as The Painter’s Algorithm, and it makes sure sure that textures appear behind and in front of eachother in the right order.

The above gif also demonstrates the renderdistance functionality that I created so that the software would be as performant as possible. In the gif the render distance is set to 700, this means that the program will only calculate and draw the upcoming 700 road-segments. Having this render distance also allowes me to have non-continuous roads, this means that I can make a road turn 360-degrees and not end up in the same place as before.