Skip to content

Renders OBJ files to a 2D display using C++, SFML library, and some magic matrices math.

Notifications You must be signed in to change notification settings

apo11o-M/Obj-File-Renderer

Repository files navigation

Obj File Renderer

Obj_File_Renderer_Demo4

What is this?

Obj File Renderer is a program that renders OBJ files to a 2D display using C++ and the SFML Library. In other words, it reads in a 3D model file that consists of the vertices and the faces data of the 3D model, do some fancy rotations, calculate the lighting of each individual faces, then project those points onto the 2D screen.

I decided to write every mathematics part from the ground up based on my understanding of linear algebra and lots of digging through the internet. And I use the SFML library to handle the actual drawing of the triangles.

Currently I am still experimenting with the concept so it still has limited features. In the future I will be constantly adding more stuff such as moveable camera and smoother lighting on the model.

Credits

Major Updates

7/13/2021

  • Implemented the Phong Shading algorithm so the pixel color is calculated based on the interpolated position and normals from the triangle's three vertices. (It looks very pretty much the same as the gouraud shading algorithm because of the gif's low resolution, and the large number of triangles this teapot model has).
  • Added a util class for all the helper functions.


7/8/2021

  • Implemented the Gouraud Shading algorithm so the surfaces looks smoother. The color at each pixel is the combined weight of each color at the triangles' vertices.
  • Reworked on how SFML renders the object.


6/26/2021

  • Added lighting to the surfaces (flat shading), the calculation is based on the angle between the individual faces with respect to the light source using dot product.


6/25/2021

  • Uses painter's algorithm so the front-facing faces that are behind others will be covered. So the model is not see-through anymore.


6/12/2021

  • Uses the surface normals to calculate the angle between the individual faces and the camera, so now only the faces that are facing the camera (instead of all of the faces) will be rendered.
  • However, this also means that some faces that are facing towards the camera but are behind other front-facing faces will also get rendered.


5/27/2021

  • Added a obj file parser to read in the data from the file and format it into something the program can use.
  • Refractered the code into using custom Vec3d and Vec2d classes instead of 2d arrays, so the code looks cleaner and more scalable.


4/28/2021

  • Hard coded some simple 3D objects to test out the algorithm.
  • Updated the method for inserting the vertices into the buffer.


4/2/2021 ~ 4/5/2021

  • Migrated the 3D model renderer from my previous python project "Simple3DModelRenderer" to here using C++ and SFML library for faster speed.
  • The ideas are the same, do the rotation for the 3D points, then project those 3D points onto a 2D screen

About

Renders OBJ files to a 2D display using C++, SFML library, and some magic matrices math.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published