Microproject on Computer Graphics
Title: 3D Object Rotation using OpenGL
Objective:
To develop a basic computer graphics application using OpenGL that displays a 3D object (e.g., cube or
pyramid) and applies rotation along different axes (X, Y, Z).
Software Requirements:
- C/C++ Compiler (Turbo C++ / GCC)
- OpenGL Utility Toolkit (GLUT)
- Code Editor (Code::Blocks / Visual Studio Code)
Hardware Requirements:
- Standard PC or Laptop
- Minimum 2 GB RAM
Theory / Working Principle:
OpenGL is an API for rendering 2D and 3D graphics.
Rotation in 3D is achieved using transformation matrices (glRotatef function).
User input can be used to rotate the object interactively (e.g., using keyboard arrows).
Implementation (C with OpenGL):
#include <GL/glut.h>
float angle = 0.0;
void display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glRotatef(angle, 1.0, 1.0, 0.0);
glBegin(GL_QUADS);
glColor3f(1, 0, 0);
glVertex3f(-0.5, -0.5, 0.5);
glVertex3f( 0.5, -0.5, 0.5);
glVertex3f( 0.5, 0.5, 0.5);
glVertex3f(-0.5, 0.5, 0.5);
glEnd();
glutSwapBuffers();
}
void timer(int value) {
angle += 1.0f;
if (angle > 360) angle -= 360;
glutPostRedisplay();
glutTimerFunc(16, timer, 0);
}
void init() {
glEnable(GL_DEPTH_TEST);
glClearColor(0.1, 0.1, 0.1, 1.0);
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutCreateWindow("3D Object Rotation");
init();
glutDisplayFunc(display);
glutTimerFunc(0, timer, 0);
glutMainLoop();
return 0;
}
Advantages:
- Helps understand the basics of 3D transformations.
- Gives hands-on practice with OpenGL and real-time rendering.
Conclusion:
This project demonstrates real-time 3D object manipulation using OpenGL, enhancing the conceptual
understanding of transformations in computer graphics.
Future Scope:
- Add lighting and shading.
- Allow keyboard control for manual rotation.
- Load 3D models from external files.