A C/OpenGL application that provides an interactive 3D environment for manipulating objects. This demo showcases real-time 3D object transformation with two UI options: a simple GLUT-based interface and a full Clay UI interface.
- 3D Object Manipulation: Transform cubes and spheres in real-time
- Dual UI Options: Simple GLUT UI (default) or full Clay UI interface
- Interactive Camera: Mouse-controlled camera rotation and zoom
- Multiple Objects: Switch between cube and sphere manipulation
- Real-time Updates: Immediate visual feedback for all transformations
- Wireframe Mode: Toggle between solid and wireframe rendering
- Coordinate System: Visual reference axes for orientation
- Built-in GLUT interface: No external UI dependencies
- Keyboard controls: Arrow keys for object manipulation
- Mode switching: Tab key to cycle through Position/Rotation/Scale/Color modes
- On-screen display: Real-time property values and controls
- Clay UI integration: Modern, responsive user interface controls
- Slider controls: Direct manipulation of object properties
- Advanced features: More sophisticated UI layout and interactions
- Left Click + Drag: Rotate camera around the scene
- Right Click + Drag: Zoom in/out
- 1/2: Select cube/sphere
- Tab: Cycle through modes (Position → Rotation → Scale → Color)
- Arrow Keys: Modify selected property in current mode
- Shift + Arrow Keys: Fine adjustment
- W: Toggle wireframe mode
- R: Reset selected object
- H: Hide/show UI overlay
- ESC: Exit application
- Clay UI Panel: Sliders for position, rotation, scale, and color
- Object Selector: Dropdown to choose between objects
- Reset Button: Reset object to default state
- Wireframe Toggle: Checkbox for rendering mode
- GCC compiler
- Make build system (or CMake)
- OpenGL development libraries
make install-deps
make install-deps-fedora
make install-deps-arch
# Ubuntu/Debian
sudo apt-get install freeglut3-dev libgl1-mesa-dev libglu1-mesa-dev build-essential
# Fedora/RHEL
sudo dnf install freeglut-devel mesa-libGL-devel mesa-libGLU-devel gcc make
# Arch Linux
sudo pacman -S freeglut mesa gcc make
make install-clay
make
# or
make simple
make full
make run
# or
./opengl_demo_simple
make run-full
# or
./opengl_demo
./demo.sh
make debug
make clean
mkdir build
cd build
cmake ..
make
make run
Or directly:
./opengl_demo
make clean-all
cpp-opengl-demo/
├── main.c # Full version with Clay UI
├── main_simple.c # Simple version with GLUT UI
├── opengl_utils.h # Header file with utility functions
├── opengl_utils.c # OpenGL utility functions
├── Makefile # Make build configuration
├── CMakeLists.txt # CMake build configuration
├── demo.sh # Demo script for easy testing
└── README.md # This file
-
Install dependencies:
make install-deps
-
Build the simple version:
make
-
Run the demo:
./demo.sh
-
Start manipulating objects:
- Press
1
or2
to select cube or sphere - Press
Tab
to cycle through modes - Use arrow keys to modify properties
- Use mouse to rotate and zoom the camera
- Press
W
to toggle wireframe mode - Press
R
to reset objects
- Press
- Lighting: Ambient and diffuse lighting with a single light source
- Depth Testing: Proper 3D depth rendering
- Material Properties: Color material for realistic object appearance
- Perspective Projection: 45-degree field of view
- Simple UI: Built-in GLUT text rendering and keyboard handling
- Full UI: Clay UI framework integration with event handling
- Responsive Design: UI adapts to window resizing
- Cube: 6-sided polyhedron with proper normals
- Sphere: UV sphere with configurable resolution
- Transformations: Position, rotation, and scale support
-
Clay library not found (Full version only):
- Install Clay UI:
make install-clay
- Or use the simple version:
make simple
- Install Clay UI:
-
OpenGL context creation failed:
- Verify graphics drivers are installed
- Check that Mesa or proprietary drivers are working
-
Compilation errors:
- Ensure all development packages are installed
- Check GCC version compatibility
- Try using CMake instead of Make if issues persist
Run with debug flags for additional information:
make debug
./opengl_demo_simple
If Make doesn't work, try CMake:
mkdir build && cd build
cmake ..
make
- Define a new
Object3D
structure inopengl_utils.h
- Add rendering function (e.g.,
draw_torus()
) inopengl_utils.c
- Update UI controls in both
main.c
andmain_simple.c
- Add object selection logic
- Simple UI: Add new keyboard controls in
main_simple.c
- Full UI: Create new Clay widgets in
main.c
- Update the UI layout as needed
- Adjust sphere resolution for better performance
- Implement object culling for large scenes
- Use display lists for static geometry
This project is provided as a demonstration of OpenGL and UI integration. Feel free to modify and extend for your own projects.
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.