A simple Python program that renders a rotating 3D wireframe cube using OpenGL.
This project demonstrates basic 3D graphics rendering using PyOpenGL. It creates a window displaying a wireframe cube that rotates in 3D space, showcasing fundamental concepts like rotation, perspective, and OpenGL drawing.
- 3D wireframe cube rendering
- Real-time rotation on X and Y axes
- Simple OpenGL setup and configuration
- Minimal, easy-to-understand code
- Python 3.x
- PyOpenGL
Install the required package using pip:
pip install PyOpenGLRun the program from the command line:
python cube.pyA 500×500 window will open displaying the rotating 3D cube. Close the window to exit the program.
The program uses GLUT (OpenGL Utility Toolkit) to:
- Create a 500×500 display window
- Initialize the OpenGL context in RGB color mode
- Draw a wireframe cube at each frame
- Apply rotation transformations (45° on X-axis, 45° on Y-axis)
- Continuously refresh the display
- Initialization: Sets up the display window and OpenGL parameters
- draw(): The display callback function that renders the cube with rotations
- Main Loop:
glutMainLoop()handles window events and continuous rendering
