Concept 3D Scene Viewer made using freeglut and C++, all you need is the freeglut development library and a few packages installed in your OS (check here). The source code is one single file, i.e., main.cpp.
Components used in this project:
- Three Primitives of geometries namely, Cube, Icosahedron and the Pyramid.
- Reshape function to maintain the shape of the geometry drawn on any window width and height.
- Lighting to imitate ambient, diffuse and specular lighting.
- Stars: Generated using point primitives kept inside a for loop with the location for the points kept random using srand() and rand().
- Mouse and keyboard callbacks to be able to perform actions on each mouse or keyboard event, to traverse around the three-dimensional world created in the code using two transform functions : Translation and Rotation.
- Linux:
xxf86vm
andg++
are required for Linux users. You can easily installlibXxf86vm
/libxxf86vm
/xxf86vm
(depending on the distro you have, package names vary oftentimes in different package families of distros) in the terminal with your package manager. Freeglut development libraries are also needed. Example:
# Fedora Workstation
sudo dnf install g++ libXxf86vm freeglut-devel
# Ubuntu 22.04 and Pop!_OS
sudo apt install g++ libxxf86vm freeglut3-dev
# Arch Linux
sudo pacman -S gcc libxxf86vm freeglut
- Windows: Windows users will be required to install
g++
using MYSYS2.mingw-w64-x86_64-gcc
contains the 64-bit binaries of g++. Use the MYSYS2 MINGW64 shell:
# MYSYS2 MINGW64 shell on Windows
pacman -S git mingw-w64-x86_64-gcc mingw-w64-x86_64-freeglut
# (Installing git is kind of redundant and optional depending on what Terminal you use for git operations !).
Note to self: (I also plan to replace MYSYS2 MINGW64 with MSVC in the longer run, to keep the development environment as native as possible).
- MacOS: Code hasn't been tested on MacOS yet.
- Linux: At the source root, run:
g++ main.cpp -lglut -lGL -lGLU
./a.out
(Linkers: glut
, GL
and GLU
).
- Windows: At the source root, run:
g++ main.cpp -lfreeglut -lopengl32 -lglu32
./a.exe
(Linkers: freeglut
, opengl32
and glu32
).
- MacOS: Code hasn't been tested on MacOS.