In this mini-project, we will create a simplified 3D model of the Taj Mahal using OpenGL and GLUT. The model is not intended to be an exact replica of the real monument. Instead, basic OpenGL primitives such as cubes and spheres are combined, scaled, and translated to create an idealized Taj Mahal-like structure.
This type of project is useful for understanding the fundamentals of Computer Graphics, 3D transformations, OpenGL primitives, and hierarchical modeling, and can be used as a VTU Computer Graphics mini-project.
1. Project Objective
The main objectives of this mini project in OpenGL are:
To learn how OpenGL primitive objects can be combined to form a larger model, use translation and scaling transformations, understand hierarchical modeling using
glPushMatrix()andglPopMatrix().To understand basic modeling using OpenGL and demonstrate the use of GLUT solid primitives such as cubes and spheres
Use above concept to create a simple representation of the Taj Mahal.
2. Software Requirements
The project can be implemented using:
- C/C++
- OpenGL
- GLUT / FreeGLUT
- A C/C++ compiler such as Visual Studio, Code::Blocks, Dev-C++, or MinGW.
3. Explanation
3.1. Creating the Bottom Base
The first component is the large bottom platform.
/* Draw the bottom box */
glPushMatrix();
glScaled(0.8, 0.04, 0.8);
glTranslatef(0.0, -30.2, 0.0);
glutSolidCube(7.0);
glPopMatrix();
A cube of size 7.0 is initially created. It is then scaled heavily along the Y-axis using: glScaled(0.8, 0.04, 0.8); This converts the cube into a thin rectangular platform. Then use translation with: glTranslatef(0.0, -30.2, 0.0);
places the platform below the main structure. Thus, the cube acts as the large base/platform of the Taj Mahal.
3.2. Creating the Main Building
The main central building is represented using a cubeglutSolidCube(2.0); which creates the main body. The translation glTranslatef(0.0, -0.6, 0.0); moves the building slightly downward along the Y-axis. The cube provides the basic central structure on which the dome is placed.
3.3 Creating the Main Dome
The main dome is created using a scaled sphere.
// main gumbaz
glPushMatrix();
glScaled(0.8, 1.0, 0.8);
glTranslatef(0.0, 1.5, 0.0);
glutSolidSphere(0.8, 80, 120);
glPopMatrix();
The sphere is scaled with glScaled(0.8, 1.0, 0.8); so that it forms a dome-like shape reduces the width of the sphere relative to its height. The translation: glTranslatef(0.0, 1.5, 0.0); moves it above the main building. The sphere is therefore used as a simple approximation of the central gumbaz (dome).
3.4. Dome Base
A small cube is placed underneath the dome.
glTranslatef(0.0, 1.0, 0.0);
glScaled(1.2, 0.25, 1.2);
glutSolidCube(0.9);
The cube is scaled in the Y direction to make it short and wide. This creates a small platform between the main building and the dome.
3.5. Dome Pointer or Spire
The top portion of the dome is represented using another scaled sphere.
// gumbaz pointer
glPushMatrix();
glScaled(0.03, 0.5, 0.03);
glTranslatef(0.0, 10.8, 0.0);
glutSolidSphere(0.4, 80, 120);
glPopMatrix();
The sphere is extremely narrow in the X and Z directions with scaling usingglScaled(0.03, 0.5, 0.03); which makes it appear like a thin vertical pointer. The result acts as the spire on top of the central dome.
3.6. Creating the Four Main Minarets
The Taj Mahal mini projects in OpenGL contains four large minarets positioned around the central building. They are placed approximately at: (+2, -1.9, +2)-
(-2, -1.9, +2)-
(-2, -1.9, -2)-
(+2, -1.9, -2)- This gives the structure a symmetrical appearance.
3.6.1 First Minaret
glPushMatrix();
glTranslated(2, -1.9, 2);
glScaled(.2, 10.5, .2);
glutSolidSphere(0.4, 80, 120);
glPopMatrix();
The sphere is heavily scaled along the Y-axis, making it look like a tall cylindrical tower. Although a cylinder would normally be a more natural primitive for a minaret, the project uses a scaled sphere as a simple modeling technique.
3.6.2 Minaret Top
A second scaled sphere is placed near the top.
glPushMatrix();
glTranslated(2, 0.8, 2);
glScaled(0.3, 1.5, 0.3);
glutSolidSphere(0.4, 80, 120);
glPopMatrix();
This produces a decorative section near the top of the minaret.
3.6.3. Remaining Three Main Minarets
The same technique is repeated for the remaining three corners.
Second Minaret
glTranslated(-2, -1.9, 2);
Third Minaret
glTranslated(-2, -1.9, -2);
Fourth Minaret
glTranslated(2, -1.9, -2);
Changing the signs of the X and Z coordinates places the towers at the four corners.
This demonstrates an important concept in 3D graphics: symmetry can be created by changing the coordinates of repeated objects rather than designing every object independently.
3.7. Creating the Short Inner Minarets
The program also creates four smaller towers closer to the center. The first is positioned at:
glTranslated(0.6, -0.5, 0.6);
Another is positioned at:
glTranslated(0.6, -0.5, -0.6);
The remaining two are:
glTranslated(-0.6, -0.5, -0.6);
and:
glTranslated(-0.6, -0.5, 0.6);
Each tower is created using:
glScaled(.2, 11.5, .2);
glutSolidSphere(0.2, 80, 120);
The smaller radius makes these towers thinner than the four external minarets.
3.8. Decorative Spheres on the Short Minarets
Each short minaret also contains a decorative upper section.
For example:
glPushMatrix();
glTranslated(0.6, 0.5, 0.6);
glScaled(0.3, 1.5, 0.3);
glutSolidSphere(0.4, 80, 120);
glPopMatrix();
The same design is repeated at the other three positions.
This produces symmetry and gives the model additional architectural detail.
4. Important OpenGL Functions Used
| Function | Purpose |
|---|---|
glPushMatrix() | Saves the current transformation matrix |
glPopMatrix() | Restores the previous transformation matrix |
glTranslatef() | Moves an object |
glTranslated() | Moves an object using double-precision parameters |
glScaled() | Changes the size of an object |
glutSolidCube() | Creates a solid cube |
glutSolidSphere() | Creates a solid sphere |
5. Conclusion
The Taj Mahal OpenGL mini-project demonstrates how basic geometric objects can be combined to create a recognizable 3D architectural structure.
Using cubes and spheres along with transformations such as glTranslatef(), glTranslated(), and glScaled(), we can construct the major components of the Taj Mahal, including its central building, dome, spire, platform, and minarets.
The project is an example of hierarchical modeling in OpenGL, where each component is independently transformed using glPushMatrix() and glPopMatrix().
Although the resulting model is a simplified representation rather than an exact architectural reconstruction, it effectively demonstrates the fundamental concepts required for a Computer Graphics / OpenGL mini-project.
Project Summary
Project Title: Taj Mahal
Technology: OpenGL + GLUT
Language: C/C++
/* Draw the bottom box */
glPushMatrix();
glScaled(0.8,0.04,0.8);
glTranslatef(0.0,-30.2,0.0);
glutSolidCube(7.0);
glPopMatrix();
//main cube
glTranslatef(0.0,-.6,0.0);
glutSolidCube(2.0);
//main gumbazz
glPushMatrix();
glScaled(0.8,1.0,0.8);
glTranslatef(0.0,1.5,0.0);
glutSolidSphere(0.8,80,120);
glPopMatrix();
glTranslatef(0.0,1.0,0.0);
glScaled(1.2,0.25,1.2);
glutSolidCube(0.9);
//gumbaz pointer
glPushMatrix();
glScaled(0.03,0.5,0.03);
glTranslatef(0.0,10.8,0.0);
glutSolidSphere(0.4,80,120);
glPopMatrix();
//Minars
glPushMatrix();
glTranslated(2,-1.9,2);
glScaled(.2,10.5,.2);
glutSolidSphere(0.4,80,120);
glPopMatrix();
//minar's sphere
glPushMatrix();
glTranslated(2,0.8,2);
glScaled(0.3,1.5,0.3);
glutSolidSphere(0.4,80,120);
glPopMatrix();
//Minars
glPushMatrix();
glTranslated(-2,-1.9,2);
glScaled(.2,10.5,.2);
glutSolidSphere(0.4,80,120);
glPopMatrix();
//minar's sphere
glPushMatrix();
glTranslated(-2,0.8,2);
glScaled(0.3,1.5,0.3);
glutSolidSphere(0.4,80,120);
glPopMatrix();
//Minars
glPushMatrix();
glTranslated(-2,-1.9,-2);
glScaled(.2,10.5,.2);
glutSolidSphere(0.4,80,120);
glPopMatrix();
//minar's sphere
glPushMatrix();
glTranslated(-2,0.8,-2);
glScaled(0.3,1.5,0.3);
glutSolidSphere(0.4,80,120);
glPopMatrix();
//Minars
glPushMatrix();
glTranslated(2,-1.9,-2);
glScaled(.2,10.5,.2);
glutSolidSphere(0.4,80,120);
glPopMatrix();
//minar's sphere
glPushMatrix();
glTranslated(2,0.8,-2);
glScaled(0.3,1.5,0.3);
glutSolidSphere(0.4,80,120);
glPopMatrix();
//short Minars
glPushMatrix();
glTranslated(0.6,-0.5,0.6);
glScaled(.2,11.5,.2);
glutSolidSphere(0.2,80,120);
glPopMatrix();
//short minar's sphere
glPushMatrix();
glTranslated(0.6,0.5,0.6);
glScaled(0.3,1.5,0.3);
glutSolidSphere(0.4,80,120);
glPopMatrix();
//short Minars
glPushMatrix();
glTranslated(0.6,-0.5,-0.6);
glScaled(.2,11.5,.2);
glutSolidSphere(0.2,80,120);
glPopMatrix();
//short minar's sphere
glPushMatrix();
glTranslated(0.6,0.5,-0.6);
glScaled(0.3,1.5,0.3);
glutSolidSphere(0.4,80,120);
glPopMatrix();
//short Minars
glPushMatrix();
glTranslated(-0.6,-0.5,-0.6);
glScaled(.2,11.5,.2);
glutSolidSphere(0.2,80,120);
glPopMatrix();
//short minar's sphere
glPushMatrix();
glTranslated(-0.6,0.5,-0.6);
glScaled(0.3,1.5,0.3);
glutSolidSphere(0.4,80,120);
glPopMatrix();
//short Minars
glPushMatrix();
glTranslated(-0.6,-0.5,0.6);
glScaled(.2,11.5,.2);
glutSolidSphere(0.2,80,120);
glPopMatrix();
//short minar's sphere
glPushMatrix();
glTranslated(-0.6,0.5,0.6);
glScaled(0.3,1.5,0.3);
glutSolidSphere(0.4,80,120);
glPopMatrix();